diff --git a/.gitignore b/.gitignore index 1a84b559..96fcd9e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ *.a *.sw* +/build +/build-* + +CMakeLists.txt.user *.cmake CMakeCache.txt CMakeFiles diff --git a/.gitmodules b/.gitmodules index 4d3518d1..495183b6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,6 @@ ignore = dirty [submodule "libraries/fc"] path = libraries/fc - url = https://github.com/peerplays-network/peerplays-fc.git + url = https://github.com/nathanhourt/peerplays-fc branch = latest-fc ignore = dirty diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f006aa0..9aa34959 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,15 @@ set( CLI_CLIENT_EXECUTABLE_NAME graphene_client ) set( GUI_CLIENT_EXECUTABLE_NAME Peerplays ) set( CUSTOM_URL_SCHEME "gcs" ) set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" ) +set( CMAKE_CXX_STANDARD 14 ) + +set( GRAPHENE_BUILD_DYNAMIC_LIBRARIES OFF CACHE BOOL + "Whether to build dynamic libraries instead of static. Applies only to chain, db, protocol, net, and utilities" ) +if( GRAPHENE_BUILD_DYNAMIC_LIBRARIES ) + set( CMAKE_POSITION_INDEPENDENT_CODE ON ) + set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" ) +endif() +set( FC_BUILD_DYNAMIC_LIBRARIES ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES} CACHE BOOL "Whether FC should build as a dynamic library rather than static" ) # http://stackoverflow.com/a/18369825 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") @@ -83,13 +92,17 @@ LIST(APPEND BOOST_COMPONENTS thread system filesystem program_options - signals serialization chrono unit_test_framework context locale) -SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" ) + +IF( ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES} ) + SET( Boost_USE_STATIC_LIBS OFF CACHE STRING "ON or OFF" ) +ELSE() + SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" ) +ENDIF() IF( WIN32 ) SET(BOOST_ROOT $ENV{BOOST_ROOT}) @@ -143,11 +156,11 @@ else( WIN32 ) # Apple AND Linux if( APPLE ) # Apple Specific Options Here message( STATUS "Configuring Peerplays on OS X" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -stdlib=libc++ -Wall" ) else( APPLE ) # Linux Specific Options Here message( STATUS "Configuring Peerplays on Linux" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -Wall" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall" ) set( rt_library rt ) #set( pthread_library pthread) set(CMAKE_LINKER_FLAGS "-pthread" CACHE STRING "Linker Flags" FORCE) diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index cf2355f1..a2d6305b 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -5,6 +5,6 @@ add_subdirectory( egenesis ) add_subdirectory( fc ) add_subdirectory( net ) add_subdirectory( plugins ) -add_subdirectory( time ) add_subdirectory( utilities ) add_subdirectory( wallet ) +add_subdirectory( protocol ) diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index 12a6616b..ffef29f3 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -12,10 +12,11 @@ add_library( graphene_app ) # need to link graphene_debug_witness because plugins aren't sufficiently isolated #246 -#target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness ) target_link_libraries( graphene_app - PUBLIC graphene_net graphene_utilities - graphene_account_history graphene_accounts_list graphene_affiliate_stats graphene_bookie graphene_debug_witness graphene_elasticsearch graphene_es_objects graphene_generate_genesis graphene_market_history ) + PUBLIC graphene_chain graphene_net graphene_utilities + fc graphene_db peerplays_sidechain + graphene_account_history graphene_accounts_list graphene_affiliate_stats graphene_bookie graphene_debug_witness graphene_elasticsearch + graphene_es_objects graphene_generate_genesis graphene_market_history ) target_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" @@ -43,7 +44,7 @@ add_library( graphene_plugin ) target_link_libraries( graphene_plugin - PUBLIC graphene_net graphene_utilities ) + PUBLIC graphene_chain graphene_net graphene_utilities ) target_include_directories( graphene_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index eac6d3b8..a8cc6c23 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -29,14 +29,16 @@ #include #include #include +#include +#include +#include #include -#include -#include -#include +#include #include #include #include +#include #include #include #include @@ -144,7 +146,7 @@ void network_broadcast_api::on_applied_block(const signed_block &b) { if (itr != _callbacks.end()) { auto block_num = b.block_num(); auto &callback = _callbacks.find(id)->second; - fc::async([capture_this, this, id, block_num, trx_num, trx, callback]() { + fc::async([capture_this, id, block_num, trx_num, trx, callback]() { callback(fc::variant(transaction_confirmation{id, block_num, trx_num, trx}, GRAPHENE_MAX_NESTED_OBJECTS)); }); @@ -164,7 +166,7 @@ void network_broadcast_api::broadcast_transaction(const signed_transaction &trx) fc::variant network_broadcast_api::broadcast_transaction_synchronous(const signed_transaction &trx) { _app.chain_database()->check_transaction_for_duplicated_operations(trx); - fc::promise::ptr prom(new fc::promise()); + fc::promise::ptr prom(fc::promise::create()); broadcast_transaction_with_callback([=](const fc::variant &v) { prom->set_value(v); }, diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 1ecdd8f7..8293c64a 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -26,8 +26,10 @@ #include #include -#include -#include +#include +#include +#include +#include #include @@ -306,10 +308,10 @@ public: auto initial_state = [this] { ilog("Initializing database..."); - if (_options->count("genesis-json")) { - std::string genesis_str; - fc::read_file_contents(_options->at("genesis-json").as(), genesis_str); - genesis_state_type genesis = fc::json::from_string(genesis_str).as(20); + if( _options->count("genesis-json") ) + { + genesis_state_type genesis = fc::json::from_file( _options->at("genesis-json").as()).as( 20 ); + std::string genesis_str = fc::json::to_string(genesis) + "\n"; bool modified_genesis = false; if (_options->count("genesis-timestamp")) { genesis.initial_timestamp = fc::time_point_sec(fc::time_point::now()) + genesis.initial_parameters.block_interval + _options->at("genesis-timestamp").as(); @@ -359,7 +361,7 @@ public: if (_options->count("enable-standby-votes-tracking")) { _chain_db->enable_standby_votes_tracking(_options->at("enable-standby-votes-tracking").as()); } - + std::string replay_reason = "reason not provided"; if (_options->count("replay-blockchain")) diff --git a/libraries/app/config_util.cpp b/libraries/app/config_util.cpp index c6dc2375..f575a9bb 100644 --- a/libraries/app/config_util.cpp +++ b/libraries/app/config_util.cpp @@ -198,7 +198,7 @@ static void load_config_file(const fc::path &config_ini_path, const bpo::options bpo::variables_map &options) { deduplicator dedup; bpo::options_description unique_options("Graphene Witness Node"); - for (const boost::shared_ptr opt : cfg_options.options()) { + for( const boost::shared_ptr& opt : cfg_options.options() ) { const boost::shared_ptr od = dedup.next(opt); if (!od) continue; @@ -241,8 +241,8 @@ static void create_new_config_file(const fc::path &config_ini_path, const fc::pa }; deduplicator dedup(modify_option_defaults); std::ofstream out_cfg(config_ini_path.preferred_string()); - std::string plugin_header_surrounding(78, '='); - for (const boost::shared_ptr opt : cfg_options.options()) { + std::string plugin_header_surrounding( 78, '=' ); + for( const boost::shared_ptr& opt : cfg_options.options() ) { const boost::shared_ptr od = dedup.next(opt); if (!od) continue; diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 77582222..78f00440 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -23,11 +23,14 @@ */ #include + #include -#include -#include -#include +#include #include +#include + +#include +#include #include @@ -2362,10 +2365,9 @@ graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type } vector account_vbos; - const time_point_sec now = _db.head_block_time(); auto vesting_range = _db.get_index_type().indices().get().equal_range(account); std::for_each(vesting_range.first, vesting_range.second, - [&account_vbos, now](const vesting_balance_object &balance) { + [&account_vbos](const vesting_balance_object &balance) { if (balance.balance.amount > 0 && balance.balance_type == vesting_balance_type::gpos && balance.balance.asset_id == asset_id_type()) account_vbos.emplace_back(balance); }); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index c12d45bf..48a41c39 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -25,8 +25,8 @@ #include -#include -#include +#include +#include #include #include diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 695eae7a..b7524a6e 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -25,7 +25,7 @@ #include -#include +#include #include diff --git a/libraries/app/include/graphene/app/full_account.hpp b/libraries/app/include/graphene/app/full_account.hpp index 2106e83b..604559f1 100644 --- a/libraries/app/include/graphene/app/full_account.hpp +++ b/libraries/app/include/graphene/app/full_account.hpp @@ -24,9 +24,11 @@ #pragma once #include +#include #include #include #include +#include namespace graphene { namespace app { using namespace graphene::chain; diff --git a/libraries/app/plugin.cpp b/libraries/app/plugin.cpp index 5155986b..18651e4b 100644 --- a/libraries/app/plugin.cpp +++ b/libraries/app/plugin.cpp @@ -23,7 +23,7 @@ */ #include -#include +#include namespace graphene { namespace app { diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 4054878c..c913b222 100755 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -6,31 +6,33 @@ set_source_files_properties( "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain add_dependencies( build_hardfork_hpp cat-parts ) file(GLOB HEADERS "include/graphene/chain/*.hpp") -file(GLOB PROTOCOL_HEADERS "include/graphene/chain/protocol/*.hpp") +list(APPEND HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp") file(GLOB CPP_FILES "*.cpp") -file(GLOB PROTOCOL_CPP_FILES "protocol/*.cpp") #if( GRAPHENE_DISABLE_UNITY_BUILD ) list(FILTER CPP_FILES EXCLUDE REGEX "[/]database[.]cpp$") #message ("--- ${CPP_FILES}") message( STATUS "Graphene database unity build disabled" ) #else( GRAPHENE_DISABLE_UNITY_BUILD ) -# list(FILTER CPP_FILES EXCLUDE REGEX ".*db_.*[.]cpp$") -# #message ("--- ${CPP_FILES}") +# set( GRAPHENE_DB_FILES +# database.cpp ) # message( STATUS "Graphene database unity build enabled" ) #endif( GRAPHENE_DISABLE_UNITY_BUILD ) -add_library( graphene_chain - ${CPP_FILES} - ${PROTOCOL_CPP_FILES} - ${HEADERS} - ${PROTOCOL_HEADERS} - "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" - ) +set( GRAPHENE_CHAIN_FILES + ${CPP_FILES} + ${HEADERS} + "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" + ) +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_chain ${GRAPHENE_CHAIN_FILES} ) +else() + add_library( graphene_chain SHARED ${GRAPHENE_CHAIN_FILES} ) +endif() add_dependencies( graphene_chain build_hardfork_hpp ) -target_link_libraries( graphene_chain graphene_db ) +target_link_libraries( graphene_chain fc graphene_db graphene_protocol ) target_include_directories( graphene_chain PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" ) @@ -46,4 +48,3 @@ INSTALL( TARGETS ARCHIVE DESTINATION lib ) INSTALL( FILES ${HEADERS} DESTINATION "include/graphene/chain" ) -INSTALL( FILES ${PROTOCOL_HEADERS} DESTINATION "include/graphene/chain/protocol" ) diff --git a/libraries/chain/account_evaluator.cpp b/libraries/chain/account_evaluator.cpp index aa199c84..c904a3c6 100644 --- a/libraries/chain/account_evaluator.cpp +++ b/libraries/chain/account_evaluator.cpp @@ -214,7 +214,7 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio if( dynamic_properties.accounts_registered_this_interval % global_properties.parameters.accounts_per_fee_scale == 0 && global_properties.parameters.account_fee_scale_bitshifts != 0 ) { - d.modify(global_properties, [&dynamic_properties](global_property_object& p) { + d.modify(global_properties, [](global_property_object& p) { p.parameters.current_fees->get().basic_fee <<= p.parameters.account_fee_scale_bitshifts; }); } diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 71ee28de..8b8f656e 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -36,10 +36,10 @@ share_type cut_fee(share_type a, uint16_t p) if( p == GRAPHENE_100_PERCENT ) return a; - fc::uint128 r(a.value); + fc::uint128_t r = a.value; r *= p; r /= GRAPHENE_100_PERCENT; - return r.to_uint64(); + return r; } void account_balance_object::adjust_balance(const asset& delta) @@ -142,7 +142,12 @@ set
account_member_index::get_address_members(const account_object& a)c return result; } -void account_member_index::object_inserted(const object& obj) +void account_member_index::object_loaded(const object& obj) +{ + object_created(obj); +} + +void account_member_index::object_created(const object& obj) { assert( dynamic_cast(&obj) ); // for debug only const account_object& a = static_cast(obj); @@ -256,7 +261,10 @@ void account_member_index::object_modified(const object& after) } -void account_referrer_index::object_inserted( const object& obj ) +void account_referrer_index::object_loaded( const object& obj ) +{ +} +void account_referrer_index::object_created( const object& obj ) { } void account_referrer_index::object_removed( const object& obj ) @@ -272,7 +280,12 @@ void account_referrer_index::object_modified( const object& after ) const uint8_t balances_by_account_index::bits = 20; const uint64_t balances_by_account_index::mask = (1ULL << balances_by_account_index::bits) - 1; -void balances_by_account_index::object_inserted( const object& obj ) +void balances_by_account_index::object_loaded( const object& obj ) +{ + object_created(obj); +} + +void balances_by_account_index::object_created( const object& obj ) { const auto& abo = dynamic_cast< const account_balance_object& >( obj ); while( balances.size() < (abo.owner.instance.value >> bits) + 1 ) diff --git a/libraries/chain/affiliate_payout.cpp b/libraries/chain/affiliate_payout.cpp index 3138117c..9375f5b1 100644 --- a/libraries/chain/affiliate_payout.cpp +++ b/libraries/chain/affiliate_payout.cpp @@ -62,15 +62,15 @@ namespace graphene { namespace chain { //ilog("Paying ${p} of ${P} for ${s} of ${r}", ("p",payout.to_uint64())("P",to_pay.value)("s",share)("r",remaining) ); remaining -= share; } - FC_ASSERT( payout.to_uint64() <= to_pay ); + FC_ASSERT( payout <= to_pay ); if( payout > 0 ) { if ( accumulator.find(affiliate) == accumulator.end() ) - accumulator[affiliate] = payout.to_uint64(); + accumulator[affiliate] = payout; else - accumulator[affiliate] += payout.to_uint64(); - to_pay -= payout.to_uint64(); - paid += payout.to_uint64(); + accumulator[affiliate] += payout; + to_pay -= payout; + paid += payout; } } FC_ASSERT( to_pay == 0 ); diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 70adbde8..1a2923c5 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -38,10 +38,11 @@ share_type asset_bitasset_data_object::max_force_settlement_volume(share_type cu if( options.maximum_force_settlement_volume == GRAPHENE_100_PERCENT ) return current_supply + force_settled_volume; - fc::uint128 volume = current_supply.value + force_settled_volume.value; + fc::uint128_t volume = current_supply.value; + volume += force_settled_volume.value; volume *= options.maximum_force_settlement_volume; volume /= GRAPHENE_100_PERCENT; - return volume.to_uint64(); + return volume; } void asset_bitasset_data_object::update_median_feeds(time_point_sec current_time) diff --git a/libraries/chain/balance_evaluator.cpp b/libraries/chain/balance_evaluator.cpp index 817d736f..8cc11b85 100644 --- a/libraries/chain/balance_evaluator.cpp +++ b/libraries/chain/balance_evaluator.cpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #include -#include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/betting_market_object.cpp b/libraries/chain/betting_market_object.cpp index d5efd56c..75613233 100644 --- a/libraries/chain/betting_market_object.cpp +++ b/libraries/chain/betting_market_object.cpp @@ -75,7 +75,7 @@ namespace mpl = boost::mpl; amount_to_match_128 += backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION - 1; amount_to_match_128 /= backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION; } - return amount_to_match_128.to_uint64(); + return amount_to_match_128; } share_type bet_object::get_approximate_matching_amount(bool round_up /* = false */) const diff --git a/libraries/chain/block_database.cpp b/libraries/chain/block_database.cpp index 7675871e..809807af 100644 --- a/libraries/chain/block_database.cpp +++ b/libraries/chain/block_database.cpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #include -#include +#include #include namespace graphene { namespace chain { diff --git a/libraries/chain/buyback.cpp b/libraries/chain/buyback.cpp index 09341fe7..152fc7bb 100644 --- a/libraries/chain/buyback.cpp +++ b/libraries/chain/buyback.cpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -#include +#include #include #include #include diff --git a/libraries/chain/committee_member_evaluator.cpp b/libraries/chain/committee_member_evaluator.cpp index 01614f99..439285b4 100644 --- a/libraries/chain/committee_member_evaluator.cpp +++ b/libraries/chain/committee_member_evaluator.cpp @@ -25,9 +25,8 @@ #include #include #include -#include -#include -#include +#include +#include #include namespace graphene { namespace chain { @@ -42,7 +41,7 @@ object_id_type committee_member_create_evaluator::do_apply( const committee_memb { try { vote_id_type vote_id; db().modify(db().get_global_properties(), [&vote_id](global_property_object& p) { - vote_id = get_next_vote_id(p, vote_id_type::committee); + vote_id = vote_id_type(vote_id_type::committee, p.next_available_vote_id++); }); const auto& new_del_object = db().create( [&]( committee_member_object& obj ){ diff --git a/libraries/chain/confidential_evaluator.cpp b/libraries/chain/confidential_evaluator.cpp index 9946b492..4be4d0e1 100644 --- a/libraries/chain/confidential_evaluator.cpp +++ b/libraries/chain/confidential_evaluator.cpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #include -#include +#include #include #include #include diff --git a/libraries/chain/custom_account_authority_evaluator.cpp b/libraries/chain/custom_account_authority_evaluator.cpp index bbf29c2c..40725828 100644 --- a/libraries/chain/custom_account_authority_evaluator.cpp +++ b/libraries/chain/custom_account_authority_evaluator.cpp @@ -126,3 +126,4 @@ void_result delete_custom_account_authority_evaluator::do_apply(const custom_acc } // namespace chain } // namespace graphene + diff --git a/libraries/chain/db_bet.cpp b/libraries/chain/db_bet.cpp index 6b14f4ff..88997a4b 100644 --- a/libraries/chain/db_bet.cpp +++ b/libraries/chain/db_bet.cpp @@ -29,6 +29,8 @@ #include #include +#include + #include #include #include @@ -132,7 +134,7 @@ void database::resolve_betting_market_group(const betting_market_group_object& b bool group_was_canceled = resolutions.begin()->second == betting_market_resolution_type::cancel; if (group_was_canceled) - modify(betting_market_group, [group_was_canceled,this](betting_market_group_object& betting_market_group_obj) { + modify(betting_market_group, [this](betting_market_group_object& betting_market_group_obj) { betting_market_group_obj.on_canceled_event(*this, false); // this cancels the betting markets }); else { @@ -149,7 +151,7 @@ void database::resolve_betting_market_group(const betting_market_group_object& b }); } - modify(betting_market_group, [group_was_canceled,this](betting_market_group_object& betting_market_group_obj) { + modify(betting_market_group, [this](betting_market_group_object& betting_market_group_obj) { betting_market_group_obj.on_graded_event(*this); }); } @@ -263,7 +265,7 @@ void database::settle_betting_market_group(const betting_market_group_object& be share_type rake_amount; if (net_profits.value > 0 && rake_account_id) { - rake_amount = ((fc::uint128_t(net_profits.value) * rake_fee_percentage + GRAPHENE_100_PERCENT - 1) / GRAPHENE_100_PERCENT).to_uint64(); + rake_amount = ((fc::uint128_t(net_profits.value) * rake_fee_percentage + GRAPHENE_100_PERCENT - 1) / GRAPHENE_100_PERCENT); share_type affiliates_share; if (rake_amount.value) affiliates_share = payout_helper.payout( bettor_id, rake_amount ); @@ -490,7 +492,7 @@ int match_bet(database& db, const bet_object& taker_bet, const bet_object& maker payout_128 += taker_amount_to_match.value; payout_128 *= GRAPHENE_BETTING_ODDS_PRECISION; payout_128 /= maker_bet.back_or_lay == bet_type::back ? maker_amount_to_match.value : taker_amount_to_match.value; - assert(payout_128.to_uint64() == maker_bet.backer_multiplier); + assert(payout_128 == maker_bet.backer_multiplier); } #endif diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 67601c2e..0e194aa6 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -26,22 +26,22 @@ #include #include -#include -#include - #include #include #include #include -#include +#include #include -#include #include #include #include -#include +#include +#include +#include + +#include namespace { @@ -819,7 +819,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx const auto& tapos_block_summary = block_summary_id_type( trx.ref_block_num )(*this); //Verify TaPoS block summary has correct ID prefix, and that this block's time is not past the expiration - FC_ASSERT( trx.ref_block_prefix == tapos_block_summary.block_id._hash[1] ); + FC_ASSERT( trx.ref_block_prefix == tapos_block_summary.block_id._hash[1].value() ); } fc::time_point_sec now = head_block_time(); @@ -832,8 +832,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_getter.cpp b/libraries/chain/db_getter.cpp index 78740c9b..28de7938 100644 --- a/libraries/chain/db_getter.cpp +++ b/libraries/chain/db_getter.cpp @@ -113,13 +113,15 @@ std::vector database::get_seeds( asset_id_type for_asset, uint8_t coun { FC_ASSERT( count_winners <= 64 ); std::string salted_string = std::string(_random_number_generator._seed) + std::to_string(for_asset.instance.value); - uint32_t* seeds = (uint32_t*)(fc::sha256::hash(salted_string)._hash); + auto seeds_hash = fc::sha256::hash(salted_string); + uint32_t* seeds = (uint32_t*)(seeds_hash._hash); std::vector result; result.reserve(64); for( int s = 0; s < 8; ++s ) { - uint32_t* sub_seeds = ( uint32_t* ) fc::sha256::hash( std::to_string( seeds[s] ) + std::to_string( for_asset.instance.value ) )._hash; + auto sub_seeds_hash = fc::sha256::hash(std::to_string(seeds[s]) + std::to_string(for_asset.instance.value)); + uint32_t* sub_seeds = (uint32_t*) sub_seeds_hash._hash; for( int ss = 0; ss < 8; ++ss ) { result.push_back(sub_seeds[ss]); } @@ -224,7 +226,8 @@ std::set database::get_sons_to_be_deregistered() { if(son.status == son_status::in_maintenance) { - auto stats = son.statistics(*this); + auto& stats = son.statistics(*this); + // TODO : We need to add a function that returns if we can deregister SON // i.e. with introduction of PW code, we have to make a decision if the SON // is needed for release of funds from the PW diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 724cad85..ce6cff41 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 @@ -104,7 +104,7 @@ #include #include -#include +#include #include #include @@ -152,8 +152,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; @@ -680,7 +680,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) p.time = genesis_state.initial_timestamp; p.dynamic_flags = 0; p.witness_budget = 0; - p.recent_slots_filled = fc::uint128::max_value(); + p.recent_slots_filled = std::numeric_limits::max(); }); create([&](global_betting_statistics_object& betting_statistics) { betting_statistics.number_of_active_events = 0; @@ -903,7 +903,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) for( const auto& handout : genesis_state.initial_balances ) { const auto asset_id = get_asset_id(handout.asset_symbol); - create([&handout,&get_asset_id,total_allocation,asset_id](balance_object& b) { + create([&handout,total_allocation,asset_id](balance_object& b) { b.balance = asset(handout.amount, asset_id); b.owner = handout.owner; }); @@ -1049,7 +1049,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) _wso.last_scheduling_block = 0; - _wso.recent_slots_filled = fc::uint128::max_value(); + _wso.recent_slots_filled = std::numeric_limits::max(); // for shuffled for( const witness_id_type& wid : get_global_properties().active_witnesses ) @@ -1076,7 +1076,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) _sso.last_scheduling_block = 0; - _sso.recent_slots_filled = fc::uint128::max_value(); + _sso.recent_slots_filled = std::numeric_limits::max(); }); assert( sso.id == son_schedule_id_type() ); diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 3f68d598..08671e6d 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -22,10 +22,6 @@ * THE SOFTWARE. */ -#include - -#include - #include #include #include @@ -51,6 +47,8 @@ #include #include +#include + namespace graphene { namespace chain { template @@ -427,7 +425,7 @@ void database::pay_workers( share_type& budget ) // worker with more votes is preferred // if two workers exactly tie for votes, worker with lower ID is preferred - std::sort(active_workers.begin(), active_workers.end(), [this](const worker_object& wa, const worker_object& wb) { + std::sort(active_workers.begin(), active_workers.end(), [](const worker_object& wa, const worker_object& wb) { share_type wa_vote = wa.approving_stake(); share_type wb_vote = wb.approving_stake(); if( wa_vote != wb_vote ) @@ -447,10 +445,10 @@ void database::pay_workers( share_type& budget ) // Note: if there is a good chance that passed_time_count == day_count, // for better performance, can avoid the 128 bit calculation by adding a check. // Since it's not the case on BitShares mainnet, we're not using a check here. - fc::uint128 pay(requested_pay.value); + fc::uint128_t pay = requested_pay.value; pay *= passed_time_count; pay /= day_count; - requested_pay = pay.to_uint64(); + requested_pay = pay; share_type actual_pay = std::min(budget, requested_pay); //ilog(" ==> Paying ${a} to worker ${w}", ("w", active_worker.id)("a", actual_pay)); @@ -839,7 +837,7 @@ void database::initialize_budget_record( fc::time_point_sec now, budget_record& budget_u128 >>= GRAPHENE_CORE_ASSET_CYCLE_RATE_BITS; share_type budget; if( budget_u128 < reserve.value ) - rec.total_budget = share_type(budget_u128.to_uint64()); + rec.total_budget = share_type(budget_u128); else rec.total_budget = reserve; @@ -905,7 +903,7 @@ void database::process_budget() if( worker_budget_u128 >= available_funds.value ) worker_budget = available_funds; else - worker_budget = worker_budget_u128.to_uint64(); + worker_budget = worker_budget_u128; rec.worker_budget = worker_budget; available_funds -= worker_budget; @@ -1050,12 +1048,12 @@ void split_fba_balance( fc::uint128_t buyback_amount_128 = fba.accumulated_fba_fees.value; buyback_amount_128 *= designated_asset_buyback_pct; buyback_amount_128 /= GRAPHENE_100_PERCENT; - share_type buyback_amount = buyback_amount_128.to_uint64(); + share_type buyback_amount = buyback_amount_128; fc::uint128_t issuer_amount_128 = fba.accumulated_fba_fees.value; issuer_amount_128 *= designated_asset_issuer_pct; issuer_amount_128 /= GRAPHENE_100_PERCENT; - share_type issuer_amount = issuer_amount_128.to_uint64(); + share_type issuer_amount = issuer_amount_128; // this assert should never fail FC_ASSERT( buyback_amount + issuer_amount <= fba.accumulated_fba_fees ); @@ -1532,7 +1530,7 @@ void schedule_pending_dividend_balances(database& db, minimum_amount_to_distribute *= 100 * GRAPHENE_1_PERCENT; minimum_amount_to_distribute /= dividend_data.options.minimum_fee_percentage; wdump((total_fee_per_asset_in_payout_asset)(dividend_data.options)); - minimum_shares_to_distribute = minimum_amount_to_distribute.to_uint64(); + minimum_shares_to_distribute = minimum_amount_to_distribute; } dlog("Processing dividend payments of asset type ${payout_asset_type}, delta balance is ${delta_balance}", ("payout_asset_type", payout_asset_type(db).symbol)("delta_balance", delta_balance)); @@ -1594,7 +1592,7 @@ void schedule_pending_dividend_balances(database& db, fc::uint128_t amount_to_credit(delta_balance.value); amount_to_credit *= holder_balance.amount.value; amount_to_credit /= total_balance_of_dividend_asset.value; - share_type full_shares_to_credit((int64_t) amount_to_credit.to_uint64()); + share_type full_shares_to_credit((int64_t) amount_to_credit); share_type shares_to_credit = (uint64_t) floor(full_shares_to_credit.value * vesting_factor); if (shares_to_credit < full_shares_to_credit) { @@ -1631,7 +1629,7 @@ void schedule_pending_dividend_balances(database& db, fc::uint128_t amount_to_credit(delta_balance.value); amount_to_credit *= holder_balance.value; amount_to_credit /= total_balance_of_dividend_asset.value; - share_type shares_to_credit((int64_t) amount_to_credit.to_uint64()); + share_type shares_to_credit((int64_t) amount_to_credit); remaining_amount_to_distribute = credit_account(db, holder_balance_object.owner, @@ -1691,7 +1689,7 @@ void schedule_pending_dividend_balances(database& db, fc::uint128_t amount_to_debit(remaining_amount_to_recover.value); amount_to_debit *= pending_balance_object.pending_balance.value; amount_to_debit /= remaining_pending_balances.value; - share_type shares_to_debit((int64_t)amount_to_debit.to_uint64()); + share_type shares_to_debit((int64_t)amount_to_debit); remaining_amount_to_recover -= shares_to_debit; remaining_pending_balances -= pending_balance_object.pending_balance; diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index 2ca49c4c..92bd15ee 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -29,7 +29,8 @@ #include #include #include -#include + +#include #include diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index ad888532..9f614815 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -575,10 +575,10 @@ asset database::calculate_market_fee( const asset_object& trade_asset, const ass if( trade_asset.options.market_fee_percent == 0 ) return trade_asset.amount(0); - fc::uint128 a(trade_amount.amount.value); + fc::uint128_t a(trade_amount.amount.value); a *= trade_asset.options.market_fee_percent; a /= GRAPHENE_100_PERCENT; - asset percent_fee = trade_asset.amount(a.to_uint64()); + asset percent_fee = trade_asset.amount(a); if( percent_fee.amount > trade_asset.options.max_market_fee ) percent_fee.amount = trade_asset.options.max_market_fee; diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index c5986fad..e1932aa0 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -24,11 +24,11 @@ #include +#include +#include +#include + #include -#include -#include -#include -#include #include #include #include @@ -39,14 +39,17 @@ #include #include #include -#include +#include #include #include #include #include #include #include - +#include +#include +#include +#include using namespace fc; using namespace graphene::chain; @@ -450,7 +453,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 ); @@ -518,7 +520,85 @@ void get_relevant_accounts( const object* obj, flat_set& accoun } case balance_object_type:{ /** these are free from any accounts */ break; - } case account_role_type:{ + } case tournament_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->creator); + accounts.insert(aobj->options.whitelist.begin(), aobj->options.whitelist.end()); + break; + } case tournament_details_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->registered_players.begin(), aobj->registered_players.end()); + std::transform(aobj->payers.begin(), aobj->payers.end(), std::inserter(accounts, accounts.end()), + [](const auto& pair) { return pair.first; }); + std::for_each(aobj->players_payers.begin(), aobj->players_payers.end(), + [&accounts](const auto& pair) { + accounts.insert(pair.first); + accounts.insert(pair.second); + }); + break; + } case match_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->players.begin(), aobj->players.end()); + std::for_each(aobj->game_winners.begin(), aobj->game_winners.end(), + [&accounts](const auto& set) { accounts.insert(set.begin(), set.end()); }); + accounts.insert(aobj->match_winners.begin(), aobj->match_winners.end()); + break; + } case game_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->players.begin(), aobj->players.end()); + accounts.insert(aobj->winners.begin(), aobj->winners.end()); + break; + } case sport_object_type: + break; + case event_group_object_type: + break; + case event_object_type: + break; + case betting_market_rules_object_type: + break; + case betting_market_group_object_type: + break; + case betting_market_object_type: + break; + case bet_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->bettor_id); + break; + } case custom_permission_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->account); + add_authority_accounts(accounts, aobj->auth); + break; + } case custom_account_authority_object_type: + break; + case offer_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->issuer); + if (aobj->bidder.valid()) + accounts.insert(*aobj->bidder); + break; + } case nft_metadata_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->owner); + if (aobj->revenue_partner.valid()) + accounts.insert(*aobj->revenue_partner); + break; + } case nft_object_type:{ + auto aobj = dynamic_cast(obj); + assert(aobj != nullptr); + accounts.insert(aobj->owner); + accounts.insert(aobj->approved); + accounts.insert(aobj->approved_operators.begin(), aobj->approved_operators.end()); + break; + } case account_role_object_type:{ const auto& aobj = dynamic_cast(obj); assert( aobj != nullptr ); accounts.insert( aobj->owner ); @@ -529,6 +609,8 @@ void get_relevant_accounts( const object* obj, flat_set& accoun assert( aobj != nullptr ); accounts.insert( aobj->son_account ); break; + } case son_proposal_object_type:{ + break; } case son_wallet_object_type:{ break; } case son_wallet_deposit_object_type:{ @@ -558,9 +640,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); @@ -572,11 +654,11 @@ 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, - ignore_custom_operation_required_auths); + ignore_custom_operation_required_auths ); break; } case impl_blinded_balance_object_type:{ const auto& aobj = dynamic_cast(obj); @@ -600,6 +682,44 @@ void get_relevant_accounts( const object* obj, flat_set& accoun break; case impl_fba_accumulator_object_type: break; + case impl_asset_dividend_data_object_type:{ + const auto& aobj = dynamic_cast(obj); + assert( aobj != nullptr ); + accounts.insert(aobj->dividend_distribution_account); + break; + } case impl_pending_dividend_payout_balance_for_holder_object_type:{ + const auto& aobj = dynamic_cast(obj); + assert( aobj != nullptr ); + accounts.insert(aobj->owner); + break; + } case impl_total_distributed_dividend_balance_object_type: + break; + case impl_betting_market_position_object_type:{ + const auto& aobj = dynamic_cast(obj); + assert( aobj != nullptr ); + accounts.insert(aobj->bettor_id); + break; + } case impl_global_betting_statistics_object_type: + break; + case impl_lottery_balance_object_type: + break; + case impl_sweeps_vesting_balance_object_type:{ + const auto& aobj = dynamic_cast(obj); + assert( aobj != nullptr ); + accounts.insert(aobj->owner); + break; + } case impl_offer_history_object_type:{ + const auto& aobj = dynamic_cast(obj); + assert( aobj != nullptr ); + accounts.insert(aobj->issuer); + if (aobj->bidder.valid()) + accounts.insert(*aobj->bidder); + break; + } case impl_son_statistics_object_type: { + break; + } case impl_son_schedule_object_type: { + break; + } case impl_nft_lottery_balance_object_type: break; default: diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 0476982c..f6b5c950 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -35,13 +35,11 @@ #include #include #include -#include +#include #include #include -#include - -#include +#include namespace graphene { namespace chain { @@ -156,7 +154,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()); @@ -427,7 +426,7 @@ void database::clear_expired_orders() auto& pays = order.balance; auto receives = (order.balance * mia.current_feed.settlement_price); receives.amount = (fc::uint128_t(receives.amount.value) * - (GRAPHENE_100_PERCENT - mia.options.force_settlement_offset_percent) / GRAPHENE_100_PERCENT).to_uint64(); + (GRAPHENE_100_PERCENT - mia.options.force_settlement_offset_percent) / GRAPHENE_100_PERCENT); assert(receives <= order.balance * mia.current_feed.settlement_price); price settlement_price = pays / receives; diff --git a/libraries/chain/db_witness_schedule.cpp b/libraries/chain/db_witness_schedule.cpp index 084c8e1d..78fddd51 100644 --- a/libraries/chain/db_witness_schedule.cpp +++ b/libraries/chain/db_witness_schedule.cpp @@ -22,12 +22,14 @@ * THE SOFTWARE. */ +#include #include #include #include #include #include -#include + +#include namespace graphene { namespace chain { @@ -267,7 +269,7 @@ void database::update_witness_schedule(const signed_block& next_block) modify(wso, [&](witness_schedule_object& _wso) { _wso.slots_since_genesis += schedule_slot; - witness_scheduler_rng rng(wso.rng_seed.data, _wso.slots_since_genesis); + witness_scheduler_rng rng(wso.rng_seed.data(), _wso.slots_since_genesis); _wso.scheduler._min_token_count = std::max(int(gpo.active_witnesses.size()) / 2, 1); @@ -332,7 +334,7 @@ void database::update_son_schedule(const signed_block& next_block) modify(sso, [&](son_schedule_object& _sso) { _sso.slots_since_genesis += schedule_slot; - witness_scheduler_rng rng(sso.rng_seed.data, _sso.slots_since_genesis); + witness_scheduler_rng rng(sso.rng_seed.data(), _sso.slots_since_genesis); _sso.scheduler._min_token_count = std::max(int(gpo.active_sons.size()) / 2, 1); @@ -391,12 +393,12 @@ uint32_t database::witness_participation_rate()const if (gpo.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SHUFFLED_ALGORITHM) { const dynamic_global_property_object& dpo = get_dynamic_global_properties(); - return uint64_t(GRAPHENE_100_PERCENT) * dpo.recent_slots_filled.popcount() / 128; + return uint64_t(GRAPHENE_100_PERCENT) * fc::popcount(dpo.recent_slots_filled) / 128; } if (gpo.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SCHEDULED_ALGORITHM) { const witness_schedule_object& wso = get_witness_schedule_object(); - return uint64_t(GRAPHENE_100_PERCENT) * wso.recent_slots_filled.popcount() / 128; + return uint64_t(GRAPHENE_100_PERCENT) * fc::popcount(wso.recent_slots_filled) / 128; } return 0; } diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index 2ae8f0e7..638df2bd 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -33,9 +33,7 @@ #include #include #include -#include - -#include +#include namespace graphene { namespace chain { database& generic_evaluator::db()const { return trx_state->db(); } diff --git a/libraries/chain/event_evaluator.cpp b/libraries/chain/event_evaluator.cpp index 28e7476d..9c2ba9f1 100644 --- a/libraries/chain/event_evaluator.cpp +++ b/libraries/chain/event_evaluator.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/exceptions.cpp b/libraries/chain/exceptions.cpp new file mode 100644 index 00000000..9009a80c --- /dev/null +++ b/libraries/chain/exceptions.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2019 BitShares Blockchain Foundation, and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +namespace graphene { namespace chain { + + // Internal exceptions + + FC_IMPLEMENT_DERIVED_EXCEPTION( internal_exception, graphene::chain::chain_exception, 3990000, "internal exception" ) + + GRAPHENE_IMPLEMENT_INTERNAL_EXCEPTION( verify_auth_max_auth_exceeded, 1, "Exceeds max authority fan-out" ) + GRAPHENE_IMPLEMENT_INTERNAL_EXCEPTION( verify_auth_account_not_found, 2, "Auth account not found" ) + + + // Public exceptions + + FC_IMPLEMENT_EXCEPTION( chain_exception, 3000000, "blockchain exception" ) + + FC_IMPLEMENT_DERIVED_EXCEPTION( database_query_exception, chain_exception, 3010000, "database query exception" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( block_validate_exception, chain_exception, 3020000, "block validation exception" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( operation_validate_exception, chain_exception, 3040000, "operation validation exception" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( operation_evaluate_exception, chain_exception, 3050000, "operation evaluation exception" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( utility_exception, chain_exception, 3060000, "utility method exception" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( undo_database_exception, chain_exception, 3070000, "undo database exception" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( unlinkable_block_exception, chain_exception, 3080000, "unlinkable block" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( black_swan_exception, chain_exception, 3090000, "black swan" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( plugin_exception, chain_exception, 3100000, "plugin exception" ) + + FC_IMPLEMENT_DERIVED_EXCEPTION( insufficient_feeds, chain_exception, 37006, "insufficient feeds" ) + + FC_IMPLEMENT_DERIVED_EXCEPTION( pop_empty_chain, undo_database_exception, 3070001, "there are no blocks to pop" ) + + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( transfer ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( from_account_not_whitelisted, transfer, 1, "owner mismatch" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( to_account_not_whitelisted, transfer, 2, "owner mismatch" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( restricted_transfer_asset, transfer, 3, "restricted transfer asset" ) + + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( limit_order_create ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( limit_order_cancel ); + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( call_order_update ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( unfilled_margin_call, call_order_update, 1, "Updating call order would trigger a margin call that cannot be fully filled" ) + + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( account_create ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( max_auth_exceeded, account_create, 1, "Exceeds max authority fan-out" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( auth_account_not_found, account_create, 2, "Auth account not found" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( buyback_incorrect_issuer, account_create, 3, "Incorrect issuer specified for account" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( buyback_already_exists, account_create, 4, "Cannot create buyback for asset which already has buyback" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( buyback_too_many_markets, account_create, 5, "Too many buyback markets" ) + + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( account_update ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( max_auth_exceeded, account_update, 1, "Exceeds max authority fan-out" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( auth_account_not_found, account_update, 2, "Auth account not found" ) + + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( account_whitelist ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( account_upgrade ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( account_transfer ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_create ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_update ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_update_bitasset ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_update_feed_producers ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_issue ); + + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_reserve ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( invalid_on_mia, asset_reserve, 1, "invalid on mia" ) + + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_fund_fee_pool ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_settle ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_global_settle ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_publish_feed ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( committee_member_create ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( witness_create ); + + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( proposal_create ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( review_period_required, proposal_create, 1, "review_period required" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( review_period_insufficient, proposal_create, 2, "review_period insufficient" ) + + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( proposal_update ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( proposal_delete ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( withdraw_permission_create ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( withdraw_permission_update ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( withdraw_permission_claim ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( withdraw_permission_delete ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( fill_order ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( global_parameters_update ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( vesting_balance_create ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( vesting_balance_withdraw ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( worker_create ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( custom ); + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( assert ); + + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( balance_claim ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( claimed_too_often, balance_claim, 1, "balance claimed too often" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( invalid_claim_amount, balance_claim, 2, "invalid claim amount" ) + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( owner_mismatch, balance_claim, 3, "owner mismatch" ) + + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( override_transfer ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( not_permitted, override_transfer, 1, "not permitted" ) + + GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( blind_transfer ); + GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( unknown_commitment, blind_transfer, 1, "Attempting to claim an unknown prior commitment" ); + + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( transfer_from_blind_operation ) + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_claim_fees_operation ) + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( bid_collateral_operation ) + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_claim_pool_operation ) + //GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( asset_update_issuer_operation ) + + #define GRAPHENE_RECODE_EXC( cause_type, effect_type ) \ + catch( const cause_type& e ) \ + { throw( effect_type( e.what(), e.get_log() ) ); } + +} } // graphene::chain diff --git a/libraries/chain/fork_database.cpp b/libraries/chain/fork_database.cpp index 1cb4f77b..b6c72221 100644 --- a/libraries/chain/fork_database.cpp +++ b/libraries/chain/fork_database.cpp @@ -23,7 +23,7 @@ */ #include #include -#include +#include namespace graphene { namespace chain { fork_database::fork_database() diff --git a/libraries/chain/genesis_state.cpp b/libraries/chain/genesis_state.cpp index 7907c79e..a8ab549c 100644 --- a/libraries/chain/genesis_state.cpp +++ b/libraries/chain/genesis_state.cpp @@ -24,8 +24,8 @@ #include -// these are required to serialize a genesis_state -#include +// this is required to serialize a genesis_state +#include namespace graphene { namespace chain { diff --git a/libraries/chain/get_config.cpp b/libraries/chain/get_config.cpp index 245d6598..2e1cb91e 100644 --- a/libraries/chain/get_config.cpp +++ b/libraries/chain/get_config.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include namespace graphene { namespace chain { @@ -74,7 +74,6 @@ fc::variant_object get_config() result[ "GRAPHENE_MAX_COLLATERAL_RATIO" ] = GRAPHENE_MAX_COLLATERAL_RATIO; result[ "GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO" ] = GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO; result[ "GRAPHENE_DEFAULT_MAX_SHORT_SQUEEZE_RATIO" ] = GRAPHENE_DEFAULT_MAX_SHORT_SQUEEZE_RATIO; - result[ "GRAPHENE_DEFAULT_MARGIN_PERIOD_SEC" ] = GRAPHENE_DEFAULT_MARGIN_PERIOD_SEC; result[ "GRAPHENE_DEFAULT_MAX_WITNESSES" ] = GRAPHENE_DEFAULT_MAX_WITNESSES; result[ "GRAPHENE_DEFAULT_MAX_COMMITTEE" ] = GRAPHENE_DEFAULT_MAX_COMMITTEE; result[ "GRAPHENE_DEFAULT_MAX_PROPOSAL_LIFETIME_SEC" ] = GRAPHENE_DEFAULT_MAX_PROPOSAL_LIFETIME_SEC; diff --git a/libraries/chain/hardfork.d/CORE_210.hf b/libraries/chain/hardfork.d/CORE_210.hf index cf3bdade..b4badbc8 100644 --- a/libraries/chain/hardfork.d/CORE_210.hf +++ b/libraries/chain/hardfork.d/CORE_210.hf @@ -1,7 +1,7 @@ // #210 Check authorities on custom_operation #ifndef HARDFORK_CORE_210_TIME #ifdef BUILD_PEERPLAYS_TESTNET -#define HARDFORK_CORE_210_TIME (fc::time_point_sec::from_iso_string("2030-01-01T00:00:00")) // (Not yet scheduled) +#define HARDFORK_CORE_210_TIME (fc::time_point_sec::from_iso_string("2021-01-01T00:00:00")) #else #define HARDFORK_CORE_210_TIME (fc::time_point_sec::from_iso_string("2030-01-01T00:00:00")) // (Not yet scheduled) #endif diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf index b8461145..1a3d234d 100644 --- a/libraries/chain/hardfork.d/GPOS.hf +++ b/libraries/chain/hardfork.d/GPOS.hf @@ -1,3 +1,4 @@ +// The value should be harmonized with the protcol constant named GPOS_PERIOD_START #ifndef HARDFORK_GPOS_TIME #ifdef BUILD_PEERPLAYS_TESTNET #define HARDFORK_GPOS_TIME (fc::time_point_sec::from_iso_string("2020-01-06T01:00:00")) diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index 5f24adeb..3f7cb984 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -22,13 +22,15 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include -#include +#include #include namespace graphene { namespace chain { class database; + class account_object; + class vesting_balance_object; /** * @class account_statistics_object @@ -321,7 +323,8 @@ namespace graphene { namespace chain { }; public: - virtual void object_inserted( const object& obj ) override; + virtual void object_loaded( const object& obj ) override; + virtual void object_created( const object& obj ) override; virtual void object_removed( const object& obj ) override; virtual void about_to_modify( const object& before ) override; virtual void object_modified( const object& after ) override; @@ -352,7 +355,8 @@ namespace graphene { namespace chain { class account_referrer_index : public secondary_index { public: - virtual void object_inserted( const object& obj ) override; + virtual void object_loaded( const object& obj ) override; + virtual void object_created( const object& obj ) override; virtual void object_removed( const object& obj ) override; virtual void about_to_modify( const object& before ) override; virtual void object_modified( const object& after ) override; @@ -393,7 +397,8 @@ namespace graphene { namespace chain { class balances_by_account_index : public secondary_index { public: - virtual void object_inserted( const object& obj ) override; + virtual void object_loaded( const object& obj ) override; + virtual void object_created( const object& obj ) override; virtual void object_removed( const object& obj ) override; virtual void about_to_modify( const object& before ) override; virtual void object_modified( const object& after ) override; @@ -541,6 +546,10 @@ namespace graphene { namespace chain { }} +MAP_OBJECT_ID_TO_TYPE(graphene::chain::account_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::account_balance_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::account_statistics_object) + FC_REFLECT_DERIVED( graphene::chain::account_object, (graphene::db::object), (membership_expiration_date)(registrar)(referrer)(lifetime_referrer) diff --git a/libraries/chain/include/graphene/chain/account_role_evaluator.hpp b/libraries/chain/include/graphene/chain/account_role_evaluator.hpp index 29c4ada6..ede10e01 100644 --- a/libraries/chain/include/graphene/chain/account_role_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/account_role_evaluator.hpp @@ -2,8 +2,8 @@ #include #include -#include -#include +#include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/account_role_object.hpp b/libraries/chain/include/graphene/chain/account_role_object.hpp index ccdfc9bc..69b6b9d6 100644 --- a/libraries/chain/include/graphene/chain/account_role_object.hpp +++ b/libraries/chain/include/graphene/chain/account_role_object.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include @@ -13,7 +13,7 @@ namespace graphene { public: static const uint8_t space_id = protocol_ids; - static const uint8_t type_id = account_role_type; + static const uint8_t type_id = account_role_object_type; account_id_type owner; std::string name; @@ -45,5 +45,7 @@ namespace graphene } // namespace chain } // namespace graphene +MAP_OBJECT_ID_TO_TYPE(graphene::chain::account_role_object) + FC_REFLECT_DERIVED(graphene::chain::account_role_object, (graphene::db::object), (owner)(name)(metadata)(allowed_operations)(whitelisted_accounts)(valid_to)) diff --git a/libraries/chain/include/graphene/chain/affiliate_payout.hpp b/libraries/chain/include/graphene/chain/affiliate_payout.hpp index 1c0ea703..d69d398b 100644 --- a/libraries/chain/include/graphene/chain/affiliate_payout.hpp +++ b/libraries/chain/include/graphene/chain/affiliate_payout.hpp @@ -23,8 +23,8 @@ */ #pragma once -#include -#include +#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/assert_evaluator.hpp b/libraries/chain/include/graphene/chain/assert_evaluator.hpp index b985a849..e4bfdd00 100644 --- a/libraries/chain/include/graphene/chain/assert_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/assert_evaluator.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/asset_evaluator.hpp b/libraries/chain/include/graphene/chain/asset_evaluator.hpp index d65d37fc..360d1cd0 100644 --- a/libraries/chain/include/graphene/chain/asset_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/asset_evaluator.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index b8b3e532..4e1cc648 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -22,11 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include -#include +#include #include +#include +#include /** * @defgroup prediction_market Prediction Market @@ -39,6 +38,9 @@ */ namespace graphene { namespace chain { + class account_object; + class asset_bitasset_data_object; + class asset_dividend_data_object; class database; class transaction_evaluation_state; using namespace graphene::db; @@ -59,7 +61,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; @@ -111,13 +113,13 @@ namespace graphene { namespace chain { string amount_to_string(share_type amount)const; /// Convert an asset to a textual representation, i.e. "123.45" string amount_to_string(const asset& amount)const - { FC_ASSERT(amount.asset_id == id); return amount_to_string(amount.amount); } + { FC_ASSERT(amount.asset_id == get_id()); return amount_to_string(amount.amount); } /// Convert an asset to a textual representation with symbol, i.e. "123.45 USD" string amount_to_pretty_string(share_type amount)const { return amount_to_string(amount) + " " + symbol; } /// Convert an asset to a textual representation with symbol, i.e. "123.45 USD" string amount_to_pretty_string(const asset &amount)const - { FC_ASSERT(amount.asset_id == id); return amount_to_pretty_string(amount.amount); } + { FC_ASSERT(amount.asset_id == get_id()); return amount_to_pretty_string(amount.amount); } uint32_t get_issuer_num()const { return issuer.instance.value; } @@ -197,7 +199,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; @@ -375,7 +377,7 @@ namespace graphene { namespace chain { { public: static const uint8_t space_id = implementation_ids; - static const uint8_t type_id = impl_asset_dividend_data_type; + static const uint8_t type_id = impl_asset_dividend_data_object_type; /// The tunable options for Dividend-paying assets are stored in this field. dividend_asset_options options; @@ -419,7 +421,7 @@ namespace graphene { namespace chain { { public: static const uint8_t space_id = implementation_ids; - static const uint8_t type_id = impl_distributed_dividend_balance_data_type; + static const uint8_t type_id = impl_total_distributed_dividend_balance_object_type; asset_id_type dividend_holder_asset_type; asset_id_type dividend_payout_asset_type; @@ -518,6 +520,14 @@ namespace graphene { namespace chain { } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::asset_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::asset_dynamic_data_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::asset_bitasset_data_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::asset_dividend_data_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::total_distributed_dividend_balance_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::lottery_balance_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::sweeps_vesting_balance_object) + FC_REFLECT_DERIVED( graphene::chain::asset_dynamic_data_object, (graphene::db::object), (current_supply)(sweeps_tickets_sold)(confidential_supply)(accumulated_fees)(fee_pool) ) diff --git a/libraries/chain/include/graphene/chain/balance_evaluator.hpp b/libraries/chain/include/graphene/chain/balance_evaluator.hpp index 9458b173..ef1491b9 100644 --- a/libraries/chain/include/graphene/chain/balance_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/balance_evaluator.hpp @@ -23,7 +23,7 @@ */ #pragma once -#include +#include #include #include #include diff --git a/libraries/chain/include/graphene/chain/balance_object.hpp b/libraries/chain/include/graphene/chain/balance_object.hpp index 38a1a649..a0f6ff23 100644 --- a/libraries/chain/include/graphene/chain/balance_object.hpp +++ b/libraries/chain/include/graphene/chain/balance_object.hpp @@ -71,6 +71,8 @@ namespace graphene { namespace chain { using balance_index = generic_index; } } +MAP_OBJECT_ID_TO_TYPE(graphene::chain::balance_object) + FC_REFLECT_DERIVED( graphene::chain::balance_object, (graphene::db::object), (owner)(balance)(vesting_policy)(last_claim_date) ) diff --git a/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp b/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp index eb245c4a..36a516d7 100644 --- a/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp @@ -23,7 +23,7 @@ */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/betting_market_object.hpp b/libraries/chain/include/graphene/chain/betting_market_object.hpp index 2abe6b20..55271ddf 100644 --- a/libraries/chain/include/graphene/chain/betting_market_object.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_object.hpp @@ -23,14 +23,17 @@ */ #pragma once -#include +#include + +#include + #include #include -#include -#include #include +#include + namespace graphene { namespace chain { class betting_market_object; class betting_market_group_object; @@ -45,7 +48,7 @@ namespace fc { namespace graphene { namespace chain { -FC_DECLARE_EXCEPTION(no_transition, 100000, "Invalid state transition"); +FC_DECLARE_EXCEPTION(no_transition, 100000); class database; struct by_event_id; @@ -717,9 +720,16 @@ inline Stream& operator>>( Stream& s, betting_market_group_object& betting_marke } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::betting_market_rules_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::betting_market_group_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::betting_market_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::bet_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::betting_market_position_object) + FC_REFLECT_DERIVED( graphene::chain::betting_market_rules_object, (graphene::db::object), (name)(description) ) FC_REFLECT_DERIVED( graphene::chain::betting_market_group_object, (graphene::db::object), (description)(event_id)(rules_id)(asset_id)(total_matched_bets_amount)(never_in_play)(delay_before_settling)(settling_time) ) FC_REFLECT_DERIVED( graphene::chain::betting_market_object, (graphene::db::object), (group_id)(description)(payout_condition)(resolution) ) FC_REFLECT_DERIVED( graphene::chain::bet_object, (graphene::db::object), (bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(back_or_lay)(end_of_delay) ) FC_REFLECT_DERIVED( graphene::chain::betting_market_position_object, (graphene::db::object), (bettor_id)(betting_market_id)(pay_if_payout_condition)(pay_if_not_payout_condition)(pay_if_canceled)(pay_if_not_canceled)(fees_collected) ) + diff --git a/libraries/chain/include/graphene/chain/block_database.hpp b/libraries/chain/include/graphene/chain/block_database.hpp index 5a1df1a1..908e453c 100644 --- a/libraries/chain/include/graphene/chain/block_database.hpp +++ b/libraries/chain/include/graphene/chain/block_database.hpp @@ -23,12 +23,13 @@ */ #pragma once #include -#include +#include #include namespace graphene { namespace chain { - class index_entry; + struct index_entry; + using namespace graphene::protocol; class block_database { diff --git a/libraries/chain/include/graphene/chain/block_summary_object.hpp b/libraries/chain/include/graphene/chain/block_summary_object.hpp index 9f79d43e..70fc5262 100644 --- a/libraries/chain/include/graphene/chain/block_summary_object.hpp +++ b/libraries/chain/include/graphene/chain/block_summary_object.hpp @@ -22,7 +22,8 @@ * THE SOFTWARE. */ #pragma once -#include +#include + #include namespace graphene { namespace chain { @@ -48,6 +49,7 @@ namespace graphene { namespace chain { } } +MAP_OBJECT_ID_TO_TYPE(graphene::chain::block_summary_object) FC_REFLECT_DERIVED( graphene::chain::block_summary_object, (graphene::db::object), (block_id) ) diff --git a/libraries/chain/include/graphene/chain/budget_record_object.hpp b/libraries/chain/include/graphene/chain/budget_record_object.hpp index 0da71ca5..eed7ce0e 100644 --- a/libraries/chain/include/graphene/chain/budget_record_object.hpp +++ b/libraries/chain/include/graphene/chain/budget_record_object.hpp @@ -22,7 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include +#include + +#include #include namespace graphene { namespace chain { @@ -67,6 +69,8 @@ class budget_record_object : public graphene::db::abstract_object +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/buyback_object.hpp b/libraries/chain/include/graphene/chain/buyback_object.hpp index 3d58429b..fa673e3b 100644 --- a/libraries/chain/include/graphene/chain/buyback_object.hpp +++ b/libraries/chain/include/graphene/chain/buyback_object.hpp @@ -23,7 +23,8 @@ */ #pragma once -#include +#include + #include #include @@ -64,6 +65,8 @@ typedef generic_index< buyback_object, buyback_multi_index_type > buyback_index; } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::buyback_object) + FC_REFLECT_DERIVED( graphene::chain::buyback_object, (graphene::db::object), (asset_to_buy) ) GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::buyback_object ) diff --git a/libraries/chain/include/graphene/chain/chain_property_object.hpp b/libraries/chain/include/graphene/chain/chain_property_object.hpp index 3c7a77ff..e9b7dc8f 100644 --- a/libraries/chain/include/graphene/chain/chain_property_object.hpp +++ b/libraries/chain/include/graphene/chain/chain_property_object.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include namespace graphene { namespace chain { @@ -42,6 +43,8 @@ class chain_property_object : public abstract_object } } +MAP_OBJECT_ID_TO_TYPE(graphene::chain::chain_property_object) + FC_REFLECT_DERIVED( graphene::chain::chain_property_object, (graphene::db::object), (chain_id) (immutable_parameters) diff --git a/libraries/chain/include/graphene/chain/committee_member_evaluator.hpp b/libraries/chain/include/graphene/chain/committee_member_evaluator.hpp index ec55b1d7..388a4364 100644 --- a/libraries/chain/include/graphene/chain/committee_member_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/committee_member_evaluator.hpp @@ -24,6 +24,7 @@ #pragma once #include #include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/committee_member_object.hpp b/libraries/chain/include/graphene/chain/committee_member_object.hpp index fe7968d3..dfbbe979 100644 --- a/libraries/chain/include/graphene/chain/committee_member_object.hpp +++ b/libraries/chain/include/graphene/chain/committee_member_object.hpp @@ -22,9 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include #include #include +#include +#include namespace graphene { namespace chain { using namespace graphene::db; @@ -71,6 +72,7 @@ namespace graphene { namespace chain { using committee_member_index = generic_index; } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::committee_member_object) FC_REFLECT_DERIVED( graphene::chain::committee_member_object, (graphene::db::object), (committee_member_account)(vote_id)(total_votes)(url) ) diff --git a/libraries/chain/include/graphene/chain/confidential_evaluator.hpp b/libraries/chain/include/graphene/chain/confidential_evaluator.hpp index bc877faf..136519c7 100644 --- a/libraries/chain/include/graphene/chain/confidential_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/confidential_evaluator.hpp @@ -23,13 +23,10 @@ */ #pragma once #include +#include namespace graphene { namespace chain { -struct transfer_to_blind_operation; -struct transfer_from_blind_operation; -struct blind_transfer_operation; - class transfer_to_blind_evaluator : public evaluator { public: diff --git a/libraries/chain/include/graphene/chain/confidential_object.hpp b/libraries/chain/include/graphene/chain/confidential_object.hpp index acdb0ba5..90df90de 100644 --- a/libraries/chain/include/graphene/chain/confidential_object.hpp +++ b/libraries/chain/include/graphene/chain/confidential_object.hpp @@ -23,8 +23,8 @@ */ #pragma once -#include -#include +#include +#include #include @@ -65,6 +65,7 @@ typedef generic_index #define GRAPHENE_MIN_UNDO_HISTORY 10 #define GRAPHENE_MAX_UNDO_HISTORY 10000 -#define GRAPHENE_MIN_BLOCK_SIZE_LIMIT (GRAPHENE_MIN_TRANSACTION_SIZE_LIMIT*5) // 5 transactions per block -#define GRAPHENE_MIN_TRANSACTION_EXPIRATION_LIMIT (GRAPHENE_MAX_BLOCK_INTERVAL * 5) // 5 transactions per block -#define GRAPHENE_BLOCKCHAIN_PRECISION uint64_t( 100000 ) +#define GRAPHENE_MAX_NESTED_OBJECTS (200) -#define GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS 5 -#define GRAPHENE_DEFAULT_TRANSFER_FEE (1*GRAPHENE_BLOCKCHAIN_PRECISION) -#define GRAPHENE_MAX_INSTANCE_ID (uint64_t(-1)>>16) -/** percentage fields are fixed point with a denominator of 10,000 */ -#define GRAPHENE_100_PERCENT 10000 -#define GRAPHENE_1_PERCENT (GRAPHENE_100_PERCENT/100) -/** NOTE: making this a power of 2 (say 2^15) would greatly accelerate fee calcs */ -#define GRAPHENE_MAX_MARKET_FEE_PERCENT GRAPHENE_100_PERCENT -#define GRAPHENE_DEFAULT_FORCE_SETTLEMENT_DELAY (60*60*24) ///< 1 day -#define GRAPHENE_DEFAULT_FORCE_SETTLEMENT_OFFSET 0 ///< 1% -#define GRAPHENE_DEFAULT_FORCE_SETTLEMENT_MAX_VOLUME (20* GRAPHENE_1_PERCENT) ///< 20% -#define GRAPHENE_DEFAULT_PRICE_FEED_LIFETIME (60*60*24) ///< 1 day -#define GRAPHENE_MAX_FEED_PRODUCERS 200 -#define GRAPHENE_DEFAULT_MAX_AUTHORITY_MEMBERSHIP 10 -#define GRAPHENE_DEFAULT_MAX_ASSET_WHITELIST_AUTHORITIES 10 -#define GRAPHENE_DEFAULT_MAX_ASSET_FEED_PUBLISHERS 10 - -/** - * These ratios are fixed point numbers with a denominator of GRAPHENE_COLLATERAL_RATIO_DENOM, the - * minimum maitenance collateral is therefore 1.001x and the default - * maintenance ratio is 1.75x - */ -///@{ -#define GRAPHENE_COLLATERAL_RATIO_DENOM 1000 -#define GRAPHENE_MIN_COLLATERAL_RATIO 1001 ///< lower than this could result in divide by 0 -#define GRAPHENE_MAX_COLLATERAL_RATIO 32000 ///< higher than this is unnecessary and may exceed int16 storage -#define GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO 1750 ///< Call when collateral only pays off 175% the debt -#define GRAPHENE_DEFAULT_MAX_SHORT_SQUEEZE_RATIO 1500 ///< Stop calling when collateral only pays off 150% of the debt -///@} -#define GRAPHENE_DEFAULT_MARGIN_PERIOD_SEC (30*60*60*24) - -#define GRAPHENE_DEFAULT_MIN_WITNESS_COUNT (11) -#define GRAPHENE_DEFAULT_MIN_COMMITTEE_MEMBER_COUNT (11) -#define GRAPHENE_DEFAULT_MIN_SON_COUNT (5) -#define GRAPHENE_DEFAULT_MAX_WITNESSES (1001) // SHOULD BE ODD -#define GRAPHENE_DEFAULT_MAX_COMMITTEE (1001) // SHOULD BE ODD -#define GRAPHENE_DEFAULT_MAX_SONS (15) -#define GRAPHENE_DEFAULT_MAX_PROPOSAL_LIFETIME_SEC (60*60*24*7*4) // Four weeks -#define GRAPHENE_DEFAULT_COMMITTEE_PROPOSAL_REVIEW_PERIOD_SEC (60*60*24*7*2) // Two weeks -#define GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE (20*GRAPHENE_1_PERCENT) -#define GRAPHENE_DEFAULT_LIFETIME_REFERRER_PERCENT_OF_FEE (30*GRAPHENE_1_PERCENT) -#define GRAPHENE_DEFAULT_MAX_BULK_DISCOUNT_PERCENT (50*GRAPHENE_1_PERCENT) -#define GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MIN ( GRAPHENE_BLOCKCHAIN_PRECISION*int64_t(1000) ) -#define GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MAX ( GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MIN*int64_t(100) ) -#define GRAPHENE_DEFAULT_CASHBACK_VESTING_PERIOD_SEC (60*60*24*365) ///< 1 year -#define GRAPHENE_DEFAULT_CASHBACK_VESTING_THRESHOLD (GRAPHENE_BLOCKCHAIN_PRECISION*int64_t(100)) -#define GRAPHENE_DEFAULT_BURN_PERCENT_OF_FEE (20*GRAPHENE_1_PERCENT) -#define GRAPHENE_WITNESS_PAY_PERCENT_PRECISION (1000000000) -#define GRAPHENE_DEFAULT_MAX_ASSERT_OPCODE 1 -#define GRAPHENE_DEFAULT_FEE_LIQUIDATION_THRESHOLD GRAPHENE_BLOCKCHAIN_PRECISION * 100; -#define GRAPHENE_DEFAULT_ACCOUNTS_PER_FEE_SCALE 1000 -#define GRAPHENE_DEFAULT_ACCOUNT_FEE_SCALE_BITSHIFTS 4 -#define GRAPHENE_DEFAULT_MAX_BUYBACK_MARKETS 4 - -#define GRAPHENE_MAX_WORKER_NAME_LENGTH 63 - -#define GRAPHENE_MAX_URL_LENGTH 127 - -#define GRAPHENE_WITNESS_SHUFFLED_ALGORITHM 0 -#define GRAPHENE_WITNESS_SCHEDULED_ALGORITHM 1 - -// counter initialization values used to derive near and far future seeds for shuffling witnesses -// we use the fractional bits of sqrt(2) in hex -#define GRAPHENE_NEAR_SCHEDULE_CTR_IV ( (uint64_t( 0x6a09 ) << 0x30) \ - | (uint64_t( 0xe667 ) << 0x20) \ - | (uint64_t( 0xf3bc ) << 0x10) \ - | (uint64_t( 0xc908 ) ) ) - -// and the fractional bits of sqrt(3) in hex -#define GRAPHENE_FAR_SCHEDULE_CTR_IV ( (uint64_t( 0xbb67 ) << 0x30) \ - | (uint64_t( 0xae85 ) << 0x20) \ - | (uint64_t( 0x84ca ) << 0x10) \ - | (uint64_t( 0xa73b ) ) ) - -// counter used to determine bits of entropy -// must be less than or equal to secret_hash_type::data_length() -#define GRAPHENE_RNG_SEED_LENGTH (160 / 8) - -/** - * every second, the fraction of burned core asset which cycles is - * GRAPHENE_CORE_ASSET_CYCLE_RATE / (1 << GRAPHENE_CORE_ASSET_CYCLE_RATE_BITS) - */ -#define GRAPHENE_CORE_ASSET_CYCLE_RATE 17 -#define GRAPHENE_CORE_ASSET_CYCLE_RATE_BITS 32 - -#define GRAPHENE_DEFAULT_WITNESS_PAY_PER_BLOCK (GRAPHENE_BLOCKCHAIN_PRECISION * int64_t( 10) ) -#define GRAPHENE_DEFAULT_WITNESS_PAY_VESTING_SECONDS (60*60*24) -#define GRAPHENE_DEFAULT_WORKER_BUDGET_PER_DAY (GRAPHENE_BLOCKCHAIN_PRECISION * int64_t(500) * 1000 ) - -#define GRAPHENE_DEFAULT_MINIMUM_FEEDS 7 - -#define GRAPHENE_MAX_INTEREST_APR uint16_t( 10000 ) +#define GRAPHENE_CURRENT_DB_VERSION "PPY2.5" +#define GRAPHENE_DEFAULT_MIN_SON_COUNT (5) #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3 -#define GRAPHENE_CURRENT_DB_VERSION "PPY2.4" - -#define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT) - -/** - * Reserved Account IDs with special meaning - */ -///@{ -/// Represents the current committee members, two-week review period -#define GRAPHENE_COMMITTEE_ACCOUNT (graphene::chain::account_id_type(0)) -/// Represents the current witnesses -#define GRAPHENE_WITNESS_ACCOUNT (graphene::chain::account_id_type(1)) -/// Represents the current committee members -#define GRAPHENE_RELAXED_COMMITTEE_ACCOUNT (graphene::chain::account_id_type(2)) -/// Represents the canonical account with NO authority (nobody can access funds in null account) -#define GRAPHENE_NULL_ACCOUNT (graphene::chain::account_id_type(3)) -/// Represents the canonical account with WILDCARD authority (anybody can access funds in temp account) -#define GRAPHENE_TEMP_ACCOUNT (graphene::chain::account_id_type(4)) -/// Represents the canonical account for specifying you will vote directly (as opposed to a proxy) -#define GRAPHENE_PROXY_TO_SELF_ACCOUNT (graphene::chain::account_id_type(5)) -/// -#define GRAPHENE_RAKE_FEE_ACCOUNT_ID (graphene::chain::account_id_type(6)) -/// Sentinel value used in the scheduler. -#define GRAPHENE_NULL_WITNESS (graphene::chain::witness_id_type(0)) -///@} - -#define GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET (asset_id_type(743)) - -#define GRAPHENE_DEFAULT_RAKE_FEE_PERCENTAGE (3*GRAPHENE_1_PERCENT) - -/** - * Betting-related constants. - * - * We store bet multipliers as fixed-precision uint32_t. These values are - * the maximum power-of-ten bet we can have on a "symmetric" market: - * (decimal) 1.0001 - 10001 - * (fractional) 1:10000 - 10000:1 - */ -///@{ -/// betting odds (multipliers) are stored as fixed-precision, divide by this to get the actual multiplier -#define GRAPHENE_BETTING_ODDS_PRECISION 10000 -/// the smallest bet multiplier we will accept -#define GRAPHENE_BETTING_MIN_MULTIPLIER 10001 -/// the largest bet multiplier we will accept -#define GRAPHENE_BETTING_MAX_MULTIPLIER 100010000 -///@} -#define GRAPHENE_DEFAULT_MIN_BET_MULTIPLIER 10100 -#define GRAPHENE_DEFAULT_MAX_BET_MULTIPLIER 10000000 -#define GRAPHENE_DEFAULT_PERMITTED_BETTING_ODDS_INCREMENTS { { 20000, 100}, /* <= 2: 0.01 */ \ - { 30000, 200}, /* <= 3: 0.02 */ \ - { 40000, 500}, /* <= 4: 0.05 */ \ - { 60000, 1000}, /* <= 6: 0.10 */ \ - { 100000, 2000}, /* <= 10: 0.20 */ \ - { 200000, 5000}, /* <= 20: 0.50 */ \ - { 300000, 10000}, /* <= 30: 1.00 */ \ - { 500000, 20000}, /* <= 50: 2.00 */ \ - { 1000000, 50000}, /* <= 100: 5.00 */ \ - { 10000000, 100000} } /* <= 1000: 10.00 */ -#define GRAPHENE_DEFAULT_BETTING_PERCENT_FEE (2 * GRAPHENE_1_PERCENT) -#define GRAPHENE_DEFAULT_LIVE_BETTING_DELAY_TIME 5 // seconds -#define GRAPHENE_MAX_NESTED_OBJECTS (200) -#define TOURNAMENT_MIN_ROUND_DELAY 0 -#define TOURNAMENT_MAX_ROUND_DELAY 600 -#define TOURNAMENT_MIN_TIME_PER_COMMIT_MOVE 0 -#define TOURNAMENT_MAN_TIME_PER_COMMIT_MOVE 600 -#define TOURNAMENT_MIN_TIME_PER_REVEAL_MOVE 0 -#define TOURNAMENT_MAX_TIME_PER_REVEAL_MOVE 600 -#define TOURNAMENT_DEFAULT_RAKE_FEE_PERCENTAGE (3*GRAPHENE_1_PERCENT) -#define TOURNAMENT_MINIMAL_RAKE_FEE_PERCENTAGE (1*GRAPHENE_1_PERCENT) -#define TOURNAMENT_MAXIMAL_RAKE_FEE_PERCENTAGE (20*GRAPHENE_1_PERCENT) -#define TOURNAMENT_MAXIMAL_REGISTRATION_DEADLINE (60*60*24*30) // seconds, 30 days -#define TOURNAMENT_MAX_NUMBER_OF_WINS 100 -#define TOURNAMENT_MAX_PLAYERS_NUMBER 256 -#define TOURNAMENT_MAX_WHITELIST_LENGTH 1000 -#define TOURNAMENT_MAX_START_TIME_IN_FUTURE (60*60*24*7*4) // 1 month -#define TOURNAMENT_MAX_START_DELAY (60*60*24*7) // 1 week -#define SON_VESTING_AMOUNT (50*GRAPHENE_BLOCKCHAIN_PRECISION) // 50 PPY -#define SON_VESTING_PERIOD (60*60*24*2) // 2 days -#define SON_DEREGISTER_TIME (60*60*12) // 12 Hours in seconds -#define SON_HEARTBEAT_FREQUENCY (60*3) // 3 minutes in seconds -#define SON_DOWN_TIME (60*3*2) // 2 Heartbeats in seconds -#define SON_BITCOIN_MIN_TX_CONFIRMATIONS (1) -#define SON_PAY_TIME (60*60*24) // 1 day -#define SON_PAY_MAX (GRAPHENE_BLOCKCHAIN_PRECISION * int64_t(200)) -#define SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE (2*GRAPHENE_1_PERCENT) -#define SWEEPS_DEFAULT_DISTRIBUTION_ASSET (graphene::chain::asset_id_type(0)) -#define SWEEPS_VESTING_BALANCE_MULTIPLIER 100000000 -#define SWEEPS_ACCUMULATOR_ACCOUNT (graphene::chain::account_id_type(0)) -#define GPOS_PERIOD (60*60*24*30*6) // 6 months -#define GPOS_SUBPERIOD (60*60*24*30) // 1 month -#define GPOS_VESTING_LOCKIN_PERIOD (60*60*24*30) // 1 month - -#define RBAC_MIN_PERMISSION_NAME_LENGTH 3 -#define RBAC_MAX_PERMISSION_NAME_LENGTH 10 -#define RBAC_MAX_PERMISSIONS_PER_ACCOUNT 5 // 5 per account -#define RBAC_MAX_ACCOUNT_AUTHORITY_LIFETIME 180*24*60*60 // 6 months -#define RBAC_MAX_AUTHS_PER_PERMISSION 15 // 15 ops linked per permission - -#define NFT_TOKEN_MIN_LENGTH 3 -#define NFT_TOKEN_MAX_LENGTH 15 -#define NFT_URI_MAX_LENGTH GRAPHENE_MAX_URL_LENGTH - -#define ACCOUNT_ROLES_MAX_PER_ACCOUNT 20 // Max 20 roles can be created by a resource owner -#define ACCOUNT_ROLES_MAX_LIFETIME 365*24*60*60 // 1 Year diff --git a/libraries/chain/include/graphene/chain/custom_account_authority_evaluator.hpp b/libraries/chain/include/graphene/chain/custom_account_authority_evaluator.hpp index 3fe1f6f9..1a15cc2c 100644 --- a/libraries/chain/include/graphene/chain/custom_account_authority_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/custom_account_authority_evaluator.hpp @@ -1,6 +1,7 @@ #pragma once #include -#include + +#include namespace graphene { @@ -35,4 +36,5 @@ public: }; } // namespace chain -} // namespace graphene \ No newline at end of file +} // namespace graphene + diff --git a/libraries/chain/include/graphene/chain/custom_account_authority_object.hpp b/libraries/chain/include/graphene/chain/custom_account_authority_object.hpp index acca8bcf..08f2d403 100644 --- a/libraries/chain/include/graphene/chain/custom_account_authority_object.hpp +++ b/libraries/chain/include/graphene/chain/custom_account_authority_object.hpp @@ -1,5 +1,6 @@ #pragma once -#include +#include + #include #include @@ -23,7 +24,6 @@ namespace graphene { namespace chain { time_point_sec valid_to; }; - struct by_id; struct by_permission_and_op; struct by_expiration; using custom_account_authority_multi_index_type = multi_index_container< @@ -51,5 +51,8 @@ namespace graphene { namespace chain { } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::custom_account_authority_object) + FC_REFLECT_DERIVED( graphene::chain::custom_account_authority_object, (graphene::db::object), - (permission_id)(operation_type)(valid_from)(valid_to) ) \ No newline at end of file + (permission_id)(operation_type)(valid_from)(valid_to) ) + diff --git a/libraries/chain/include/graphene/chain/custom_evaluator.hpp b/libraries/chain/include/graphene/chain/custom_evaluator.hpp index 968f6e48..f9efe76e 100644 --- a/libraries/chain/include/graphene/chain/custom_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/custom_evaluator.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/custom_permission_evaluator.hpp b/libraries/chain/include/graphene/chain/custom_permission_evaluator.hpp index c9bc2801..3e054e63 100644 --- a/libraries/chain/include/graphene/chain/custom_permission_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/custom_permission_evaluator.hpp @@ -1,6 +1,8 @@ #pragma once + #include -#include + +#include namespace graphene { @@ -35,4 +37,5 @@ public: }; } // namespace chain -} // namespace graphene \ No newline at end of file +} // namespace graphene + diff --git a/libraries/chain/include/graphene/chain/custom_permission_object.hpp b/libraries/chain/include/graphene/chain/custom_permission_object.hpp index 72789ef4..ab35377c 100644 --- a/libraries/chain/include/graphene/chain/custom_permission_object.hpp +++ b/libraries/chain/include/graphene/chain/custom_permission_object.hpp @@ -1,5 +1,9 @@ #pragma once -#include + +#include + +#include + #include #include @@ -25,7 +29,6 @@ namespace graphene { namespace chain { authority auth; }; - struct by_id; struct by_account_and_permission; using custom_permission_multi_index_type = multi_index_container< custom_permission_object, @@ -45,5 +48,8 @@ namespace graphene { namespace chain { } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::custom_permission_object) + FC_REFLECT_DERIVED( graphene::chain::custom_permission_object, (graphene::db::object), - (account)(permission_name)(auth) ) \ No newline at end of file + (account)(permission_name)(auth) ) + diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 50975174..04006f9d 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #pragma once + #include #include #include @@ -30,18 +31,20 @@ #include #include #include +#include #include #include #include + +#include +#include +#include + #include #include -#include - -#include - #include #include @@ -51,6 +54,15 @@ namespace graphene { namespace chain { using graphene::db::object; class op_evaluator; class transaction_evaluation_state; + class proposal_object; + class operation_history_object; + class chain_property_object; + class witness_schedule_object; + class witness_object; + class force_settlement_object; + class limit_order_object; + class call_order_object; + class account_role_object; struct budget_record; @@ -334,11 +346,53 @@ namespace graphene { namespace chain { void initialize_indexes(); void init_genesis(const genesis_state_type& genesis_state = genesis_state_type()); + /** + * @brief Register a new evaluator to the evaluator chain for its operation type + * @tparam EvaluatorType An evaluator type which will be used to evaluate its declared operation type + * @return If registering an evaluator for an operation that already has an evaluator, returns a handle for + * the newly added evaluator which can be used to delete it later. + * + * This method registers a new evaluator type with tthe database. The evaluator specifies an operation type + * which it should be used to evaluate. The evaluator will be instantiated each time an operaton of the + * appropriate type is processed and used to evaluate the operation. + * + * This method may be called more than once with multiple evaluator types for a given operation type. When + * multiple evaluator types are registered for a given operation type, they will all execute in the order of + * registration; however, only the return value of the first registered evaluator will be returned; return + * values of subsequently registered evaluators will be silently dropped. + * + * The first evaluator registered for a given operation type is permanent, and is the only evaluator which + * can return a value. Subsequent (auxiliary) evaluators for that operation type can be deleted at runtime + * by calling @ref delete_evaluator() with the evaluator_handle obtained when registering the evaluator. + */ template - void register_evaluator() + optional register_evaluator() { - _operation_evaluators[ - operation::tag::value].reset( new op_evaluator_impl() ); + auto& eval_ptr = _operation_evaluators[operation::tag::value]; + if (eval_ptr == nullptr) + eval_ptr = std::make_unique>(); + else + return eval_ptr->append_evaluator(std::make_unique>()); + return {}; + } + + /** + * @brief Delete an auxiliary evaluator + * @param handle The evaluator handle for the evaluator to delete, as returned by @ref register_evaluator + * + * Auxiliary evaluators, or the second and subsequent evaluators registered for a given operation type, + * can be deleted so that they no longer execute when operations of the relevant type are processed. + * + * If it may be desired to delete an auxiliary evaluator, retain the evaluator handle obtained when the + * evaluator was initially registered and when it is necessary to delete the evaluator, pass the handle + * to this function. + * + * The evaluator will have been deleted by the time this function returns. + */ + void delete_evaluator(op_evaluator::evaluator_handle&& handle) + { + if ((uint64_t)handle.get_operation_type() < _operation_evaluators.size()) + _operation_evaluators[handle.get_operation_type()]->delete_evaluator(std::move(handle)); } //////////////////// db_balance.cpp //////////////////// diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index af90517e..ca13a1d3 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -24,14 +24,17 @@ #pragma once #include #include -#include +#include namespace graphene { namespace chain { class database; - struct signed_transaction; class generic_evaluator; class transaction_evaluation_state; + class account_object; + class account_statistics_object; + class asset_object; + class asset_dynamic_data_object; class generic_evaluator { @@ -119,8 +122,41 @@ namespace graphene { namespace chain { class op_evaluator { + protected: + unique_ptr next_evaluator; public: + class evaluator_handle { + // Move-only semantics, and only friends can construct + evaluator_handle(const op_evaluator* pointer, operation::tag_type type) + : pointer(pointer), operation_type(type) {} + evaluator_handle(const evaluator_handle&) = delete; + evaluator_handle& operator=(const evaluator_handle&) = delete; + + friend class op_evaluator; + template + friend class op_evaluator_impl; + + // Pointer to the handled evaluator + const op_evaluator* pointer; + // Tag of the handled evaluator + operation::tag_type operation_type; + + public: + evaluator_handle(evaluator_handle&&) = default; + evaluator_handle& operator=(evaluator_handle&&) = default; + + operation::tag_type get_operation_type() const { return operation_type; } + }; + virtual ~op_evaluator(){} + virtual evaluator_handle append_evaluator(unique_ptr next_evaluator) = 0; + virtual void delete_evaluator(evaluator_handle&& handle) { + if (next_evaluator.get() == handle.pointer) + // Next evaluator in chain is the one to delete. Move its next pointer into ours, and unique_ptr will delete the one that's going away. + next_evaluator = std::move(next_evaluator->next_evaluator); + else + next_evaluator->delete_evaluator(std::move(handle)); + } virtual operation_result evaluate(transaction_evaluation_state& eval_state, const operation& op, bool apply) = 0; }; @@ -128,10 +164,21 @@ namespace graphene { namespace chain { class op_evaluator_impl : public op_evaluator { public: + virtual evaluator_handle append_evaluator(unique_ptr next_evaluator) override { + if (this->next_evaluator == nullptr) { + this->next_evaluator = std::move(next_evaluator); + return evaluator_handle(this->next_evaluator.get(), operation::tag::value); + } else { + return this->next_evaluator->append_evaluator(std::move(next_evaluator)); + } + } virtual operation_result evaluate(transaction_evaluation_state& eval_state, const operation& op, bool apply = true) override { T eval; - return eval.start_evaluate(eval_state, op, apply); + auto result = eval.start_evaluate(eval_state, op, apply); + if (this->next_evaluator != nullptr) + this->next_evaluator->evaluate(eval_state, op, apply); + return result; } }; diff --git a/libraries/chain/include/graphene/chain/event_evaluator.hpp b/libraries/chain/include/graphene/chain/event_evaluator.hpp index 876ee94d..4dfae857 100644 --- a/libraries/chain/include/graphene/chain/event_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/event_evaluator.hpp @@ -23,9 +23,11 @@ */ #pragma once -#include #include #include +#include + +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/event_group_evaluator.hpp b/libraries/chain/include/graphene/chain/event_group_evaluator.hpp index 65ff528e..2e529f66 100644 --- a/libraries/chain/include/graphene/chain/event_group_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/event_group_evaluator.hpp @@ -23,7 +23,7 @@ */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/event_group_object.hpp b/libraries/chain/include/graphene/chain/event_group_object.hpp index 5f472e07..257cac21 100644 --- a/libraries/chain/include/graphene/chain/event_group_object.hpp +++ b/libraries/chain/include/graphene/chain/event_group_object.hpp @@ -23,9 +23,11 @@ */ #pragma once -#include +#include + #include #include + #include namespace graphene { namespace chain { @@ -58,4 +60,6 @@ typedef multi_index_container< typedef generic_index event_group_object_index; } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::event_group_object) + FC_REFLECT_DERIVED( graphene::chain::event_group_object, (graphene::db::object), (name)(sport_id) ) diff --git a/libraries/chain/include/graphene/chain/event_object.hpp b/libraries/chain/include/graphene/chain/event_object.hpp index 56330029..21b76a9f 100644 --- a/libraries/chain/include/graphene/chain/event_object.hpp +++ b/libraries/chain/include/graphene/chain/event_object.hpp @@ -23,14 +23,17 @@ */ #pragma once -#include +#include + +#include + #include #include -#include -#include #include +#include + namespace graphene { namespace chain { class event_object; } } @@ -158,6 +161,9 @@ typedef generic_index event_object_ return s; } } } // graphene::chain -FC_REFLECT(graphene::chain::event_object, (name)(season)(start_time)(event_group_id)(at_least_one_betting_market_group_settled)(scores)) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::event_object) + +FC_REFLECT_DERIVED(graphene::chain::event_object, (graphene::db::object), + (name)(season)(start_time)(event_group_id)(at_least_one_betting_market_group_settled)(scores)) diff --git a/libraries/chain/include/graphene/chain/exceptions.hpp b/libraries/chain/include/graphene/chain/exceptions.hpp index 406a235e..26804f46 100644 --- a/libraries/chain/include/graphene/chain/exceptions.hpp +++ b/libraries/chain/include/graphene/chain/exceptions.hpp @@ -25,7 +25,10 @@ #include #include -#include +#include +#include +#include +#include #define GRAPHENE_ASSERT( expr, exc_type, FORMAT, ... ) \ FC_MULTILINE_MACRO_BEGIN \ @@ -33,15 +36,26 @@ FC_THROW_EXCEPTION( exc_type, FORMAT, __VA_ARGS__ ); \ FC_MULTILINE_MACRO_END - #define GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( op_name ) \ FC_DECLARE_DERIVED_EXCEPTION( \ + op_name ## _validate_exception, \ + graphene::chain::operation_validate_exception, \ + 3040000 + 100 * operation::tag< op_name ## _operation >::value \ + ) \ + FC_DECLARE_DERIVED_EXCEPTION( \ + op_name ## _evaluate_exception, \ + graphene::chain::operation_evaluate_exception, \ + 3050000 + 100 * operation::tag< op_name ## _operation >::value \ + ) + +#define GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( op_name ) \ + FC_IMPLEMENT_DERIVED_EXCEPTION( \ op_name ## _validate_exception, \ graphene::chain::operation_validate_exception, \ 3040000 + 100 * operation::tag< op_name ## _operation >::value, \ #op_name "_operation validation exception" \ ) \ - FC_DECLARE_DERIVED_EXCEPTION( \ + FC_IMPLEMENT_DERIVED_EXCEPTION( \ op_name ## _evaluate_exception, \ graphene::chain::operation_evaluate_exception, \ 3050000 + 100 * operation::tag< op_name ## _operation >::value, \ @@ -50,6 +64,14 @@ #define GRAPHENE_DECLARE_OP_VALIDATE_EXCEPTION( exc_name, op_name, seqnum, msg ) \ FC_DECLARE_DERIVED_EXCEPTION( \ + op_name ## _ ## exc_name, \ + graphene::chain::op_name ## _validate_exception, \ + 3040000 + 100 * operation::tag< op_name ## _operation >::value \ + + seqnum \ + ) + +#define GRAPHENE_IMPLEMENT_OP_VALIDATE_EXCEPTION( exc_name, op_name, seqnum, msg ) \ + FC_IMPLEMENT_DERIVED_EXCEPTION( \ op_name ## _ ## exc_name, \ graphene::chain::op_name ## _validate_exception, \ 3040000 + 100 * operation::tag< op_name ## _operation >::value \ @@ -59,6 +81,14 @@ #define GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( exc_name, op_name, seqnum, msg ) \ FC_DECLARE_DERIVED_EXCEPTION( \ + op_name ## _ ## exc_name, \ + graphene::chain::op_name ## _evaluate_exception, \ + 3050000 + 100 * operation::tag< op_name ## _operation >::value \ + + seqnum \ + ) + +#define GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( exc_name, op_name, seqnum, msg ) \ + FC_IMPLEMENT_DERIVED_EXCEPTION( \ op_name ## _ ## exc_name, \ graphene::chain::op_name ## _evaluate_exception, \ 3050000 + 100 * operation::tag< op_name ## _operation >::value \ @@ -91,30 +121,21 @@ namespace graphene { namespace chain { - FC_DECLARE_EXCEPTION( chain_exception, 3000000, "blockchain exception" ) - FC_DECLARE_DERIVED_EXCEPTION( database_query_exception, graphene::chain::chain_exception, 3010000, "database query exception" ) - FC_DECLARE_DERIVED_EXCEPTION( block_validate_exception, graphene::chain::chain_exception, 3020000, "block validation exception" ) - FC_DECLARE_DERIVED_EXCEPTION( transaction_exception, graphene::chain::chain_exception, 3030000, "transaction validation exception" ) - FC_DECLARE_DERIVED_EXCEPTION( operation_validate_exception, graphene::chain::chain_exception, 3040000, "operation validation exception" ) - FC_DECLARE_DERIVED_EXCEPTION( operation_evaluate_exception, graphene::chain::chain_exception, 3050000, "operation evaluation exception" ) - FC_DECLARE_DERIVED_EXCEPTION( utility_exception, graphene::chain::chain_exception, 3060000, "utility method exception" ) - FC_DECLARE_DERIVED_EXCEPTION( undo_database_exception, graphene::chain::chain_exception, 3070000, "undo database exception" ) - FC_DECLARE_DERIVED_EXCEPTION( unlinkable_block_exception, graphene::chain::chain_exception, 3080000, "unlinkable block" ) - FC_DECLARE_DERIVED_EXCEPTION( black_swan_exception, graphene::chain::chain_exception, 3090000, "black swan" ) - FC_DECLARE_DERIVED_EXCEPTION( plugin_exception, graphene::chain::chain_exception, 3100000, "plugin exception" ) + FC_DECLARE_EXCEPTION( chain_exception, 3000000 ) + FC_DECLARE_DERIVED_EXCEPTION( database_query_exception, chain_exception, 3010000 ) + FC_DECLARE_DERIVED_EXCEPTION( block_validate_exception, chain_exception, 3020000 ) + FC_DECLARE_DERIVED_EXCEPTION( transaction_exception, chain_exception, 3030000 ) + FC_DECLARE_DERIVED_EXCEPTION( operation_validate_exception, chain_exception, 3040000 ) + FC_DECLARE_DERIVED_EXCEPTION( operation_evaluate_exception, chain_exception, 3050000 ) + FC_DECLARE_DERIVED_EXCEPTION( utility_exception, chain_exception, 3060000 ) + FC_DECLARE_DERIVED_EXCEPTION( undo_database_exception, chain_exception, 3070000 ) + FC_DECLARE_DERIVED_EXCEPTION( unlinkable_block_exception, chain_exception, 3080000 ) + FC_DECLARE_DERIVED_EXCEPTION( black_swan_exception, chain_exception, 3090000 ) + FC_DECLARE_DERIVED_EXCEPTION( plugin_exception, chain_exception, 3100000 ) - FC_DECLARE_DERIVED_EXCEPTION( tx_missing_active_auth, graphene::chain::transaction_exception, 3030001, "missing required active authority" ) - FC_DECLARE_DERIVED_EXCEPTION( tx_missing_owner_auth, graphene::chain::transaction_exception, 3030002, "missing required owner authority" ) - FC_DECLARE_DERIVED_EXCEPTION( tx_missing_other_auth, graphene::chain::transaction_exception, 3030003, "missing required other authority" ) - FC_DECLARE_DERIVED_EXCEPTION( tx_irrelevant_sig, graphene::chain::transaction_exception, 3030004, "irrelevant signature included" ) - FC_DECLARE_DERIVED_EXCEPTION( tx_duplicate_sig, graphene::chain::transaction_exception, 3030005, "duplicate signature included" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_committee_approval, graphene::chain::transaction_exception, 3030006, "committee account cannot directly approve transaction" ) - FC_DECLARE_DERIVED_EXCEPTION( insufficient_fee, graphene::chain::transaction_exception, 3030007, "insufficient fee" ) + FC_DECLARE_DERIVED_EXCEPTION( insufficient_feeds, chain_exception, 37006 ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_pts_address, graphene::chain::utility_exception, 3060001, "invalid pts address" ) - FC_DECLARE_DERIVED_EXCEPTION( insufficient_feeds, graphene::chain::chain_exception, 37006, "insufficient feeds" ) - - FC_DECLARE_DERIVED_EXCEPTION( pop_empty_chain, graphene::chain::undo_database_exception, 3070001, "there are no blocks to pop" ) + FC_DECLARE_DERIVED_EXCEPTION( pop_empty_chain, undo_database_exception, 3070001 ) GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( transfer ); GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( from_account_not_whitelisted, transfer, 1, "owner mismatch" ) @@ -185,93 +206,11 @@ namespace graphene { namespace chain { GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( blind_transfer ); GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( unknown_commitment, blind_transfer, 1, "Attempting to claim an unknown prior commitment" ); - /* - FC_DECLARE_DERIVED_EXCEPTION( addition_overflow, graphene::chain::chain_exception, 30002, "addition overflow" ) - FC_DECLARE_DERIVED_EXCEPTION( subtraction_overflow, graphene::chain::chain_exception, 30003, "subtraction overflow" ) - FC_DECLARE_DERIVED_EXCEPTION( asset_type_mismatch, graphene::chain::chain_exception, 30004, "asset/price mismatch" ) - FC_DECLARE_DERIVED_EXCEPTION( unsupported_chain_operation, graphene::chain::chain_exception, 30005, "unsupported chain operation" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_transaction, graphene::chain::chain_exception, 30006, "unknown transaction" ) - FC_DECLARE_DERIVED_EXCEPTION( duplicate_transaction, graphene::chain::chain_exception, 30007, "duplicate transaction" ) - FC_DECLARE_DERIVED_EXCEPTION( zero_amount, graphene::chain::chain_exception, 30008, "zero amount" ) - FC_DECLARE_DERIVED_EXCEPTION( zero_price, graphene::chain::chain_exception, 30009, "zero price" ) - FC_DECLARE_DERIVED_EXCEPTION( asset_divide_by_self, graphene::chain::chain_exception, 30010, "asset divide by self" ) - FC_DECLARE_DERIVED_EXCEPTION( asset_divide_by_zero, graphene::chain::chain_exception, 30011, "asset divide by zero" ) - FC_DECLARE_DERIVED_EXCEPTION( new_database_version, graphene::chain::chain_exception, 30012, "new database version" ) - FC_DECLARE_DERIVED_EXCEPTION( unlinkable_block, graphene::chain::chain_exception, 30013, "unlinkable block" ) - FC_DECLARE_DERIVED_EXCEPTION( price_out_of_range, graphene::chain::chain_exception, 30014, "price out of range" ) - - FC_DECLARE_DERIVED_EXCEPTION( block_numbers_not_sequential, graphene::chain::chain_exception, 30015, "block numbers not sequential" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_previous_block_id, graphene::chain::chain_exception, 30016, "invalid previous block" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_block_time, graphene::chain::chain_exception, 30017, "invalid block time" ) - FC_DECLARE_DERIVED_EXCEPTION( time_in_past, graphene::chain::chain_exception, 30018, "time is in the past" ) - FC_DECLARE_DERIVED_EXCEPTION( time_in_future, graphene::chain::chain_exception, 30019, "time is in the future" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_block_digest, graphene::chain::chain_exception, 30020, "invalid block digest" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_committee_member_signee, graphene::chain::chain_exception, 30021, "invalid committee_member signee" ) - FC_DECLARE_DERIVED_EXCEPTION( failed_checkpoint_verification, graphene::chain::chain_exception, 30022, "failed checkpoint verification" ) - FC_DECLARE_DERIVED_EXCEPTION( wrong_chain_id, graphene::chain::chain_exception, 30023, "wrong chain id" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_block, graphene::chain::chain_exception, 30024, "unknown block" ) - FC_DECLARE_DERIVED_EXCEPTION( block_older_than_undo_history, graphene::chain::chain_exception, 30025, "block is older than our undo history allows us to process" ) - - FC_DECLARE_EXCEPTION( evaluation_error, 31000, "Evaluation Error" ) - FC_DECLARE_DERIVED_EXCEPTION( negative_deposit, graphene::chain::evaluation_error, 31001, "negative deposit" ) - FC_DECLARE_DERIVED_EXCEPTION( not_a_committee_member, graphene::chain::evaluation_error, 31002, "not a committee_member" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_balance_record, graphene::chain::evaluation_error, 31003, "unknown balance record" ) - FC_DECLARE_DERIVED_EXCEPTION( insufficient_funds, graphene::chain::evaluation_error, 31004, "insufficient funds" ) - FC_DECLARE_DERIVED_EXCEPTION( missing_signature, graphene::chain::evaluation_error, 31005, "missing signature" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_claim_password, graphene::chain::evaluation_error, 31006, "invalid claim password" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_withdraw_condition, graphene::chain::evaluation_error, 31007, "invalid withdraw condition" ) - FC_DECLARE_DERIVED_EXCEPTION( negative_withdraw, graphene::chain::evaluation_error, 31008, "negative withdraw" ) - FC_DECLARE_DERIVED_EXCEPTION( not_an_active_committee_member, graphene::chain::evaluation_error, 31009, "not an active committee_member" ) - FC_DECLARE_DERIVED_EXCEPTION( expired_transaction, graphene::chain::evaluation_error, 31010, "expired transaction" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_transaction_expiration, graphene::chain::evaluation_error, 31011, "invalid transaction expiration" ) - FC_DECLARE_DERIVED_EXCEPTION( oversized_transaction, graphene::chain::evaluation_error, 31012, "transaction exceeded the maximum transaction size" ) - - FC_DECLARE_DERIVED_EXCEPTION( invalid_account_name, graphene::chain::evaluation_error, 32001, "invalid account name" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_account_id, graphene::chain::evaluation_error, 32002, "unknown account id" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_account_name, graphene::chain::evaluation_error, 32003, "unknown account name" ) - FC_DECLARE_DERIVED_EXCEPTION( missing_parent_account_signature, graphene::chain::evaluation_error, 32004, "missing parent account signature" ) - FC_DECLARE_DERIVED_EXCEPTION( parent_account_retracted, graphene::chain::evaluation_error, 32005, "parent account retracted" ) - FC_DECLARE_DERIVED_EXCEPTION( account_expired, graphene::chain::evaluation_error, 32006, "account expired" ) - FC_DECLARE_DERIVED_EXCEPTION( account_already_registered, graphene::chain::evaluation_error, 32007, "account already registered" ) - FC_DECLARE_DERIVED_EXCEPTION( account_key_in_use, graphene::chain::evaluation_error, 32008, "account key already in use" ) - FC_DECLARE_DERIVED_EXCEPTION( account_retracted, graphene::chain::evaluation_error, 32009, "account retracted" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_parent_account_name, graphene::chain::evaluation_error, 32010, "unknown parent account name" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_committee_member_slate, graphene::chain::evaluation_error, 32011, "unknown committee_member slate" ) - FC_DECLARE_DERIVED_EXCEPTION( too_may_committee_members_in_slate, graphene::chain::evaluation_error, 32012, "too many committee_members in slate" ) - FC_DECLARE_DERIVED_EXCEPTION( pay_balance_remaining, graphene::chain::evaluation_error, 32013, "pay balance remaining" ) - - FC_DECLARE_DERIVED_EXCEPTION( not_a_committee_member_signature, graphene::chain::evaluation_error, 33002, "not committee_members signature" ) - - FC_DECLARE_DERIVED_EXCEPTION( invalid_precision, graphene::chain::evaluation_error, 35001, "invalid precision" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_asset_symbol, graphene::chain::evaluation_error, 35002, "invalid asset symbol" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_asset_id, graphene::chain::evaluation_error, 35003, "unknown asset id" ) - FC_DECLARE_DERIVED_EXCEPTION( asset_symbol_in_use, graphene::chain::evaluation_error, 35004, "asset symbol in use" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_asset_amount, graphene::chain::evaluation_error, 35005, "invalid asset amount" ) - FC_DECLARE_DERIVED_EXCEPTION( negative_issue, graphene::chain::evaluation_error, 35006, "negative issue" ) - FC_DECLARE_DERIVED_EXCEPTION( over_issue, graphene::chain::evaluation_error, 35007, "over issue" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_asset_symbol, graphene::chain::evaluation_error, 35008, "unknown asset symbol" ) - FC_DECLARE_DERIVED_EXCEPTION( asset_id_in_use, graphene::chain::evaluation_error, 35009, "asset id in use" ) - FC_DECLARE_DERIVED_EXCEPTION( not_user_issued, graphene::chain::evaluation_error, 35010, "not user issued" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_asset_name, graphene::chain::evaluation_error, 35011, "invalid asset name" ) - - FC_DECLARE_DERIVED_EXCEPTION( committee_member_vote_limit, graphene::chain::evaluation_error, 36001, "committee_member_vote_limit" ) - FC_DECLARE_DERIVED_EXCEPTION( insufficient_fee, graphene::chain::evaluation_error, 36002, "insufficient fee" ) - FC_DECLARE_DERIVED_EXCEPTION( negative_fee, graphene::chain::evaluation_error, 36003, "negative fee" ) - FC_DECLARE_DERIVED_EXCEPTION( missing_deposit, graphene::chain::evaluation_error, 36004, "missing deposit" ) - FC_DECLARE_DERIVED_EXCEPTION( insufficient_relay_fee, graphene::chain::evaluation_error, 36005, "insufficient relay fee" ) - - FC_DECLARE_DERIVED_EXCEPTION( invalid_market, graphene::chain::evaluation_error, 37001, "invalid market" ) - FC_DECLARE_DERIVED_EXCEPTION( unknown_market_order, graphene::chain::evaluation_error, 37002, "unknown market order" ) - FC_DECLARE_DERIVED_EXCEPTION( shorting_base_shares, graphene::chain::evaluation_error, 37003, "shorting base shares" ) - FC_DECLARE_DERIVED_EXCEPTION( insufficient_collateral, graphene::chain::evaluation_error, 37004, "insufficient collateral" ) - FC_DECLARE_DERIVED_EXCEPTION( insufficient_depth, graphene::chain::evaluation_error, 37005, "insufficient depth" ) - FC_DECLARE_DERIVED_EXCEPTION( insufficient_feeds, graphene::chain::evaluation_error, 37006, "insufficient feeds" ) - FC_DECLARE_DERIVED_EXCEPTION( invalid_feed_price, graphene::chain::evaluation_error, 37007, "invalid feed price" ) - - FC_DECLARE_DERIVED_EXCEPTION( price_multiplication_overflow, graphene::chain::evaluation_error, 38001, "price multiplication overflow" ) - FC_DECLARE_DERIVED_EXCEPTION( price_multiplication_underflow, graphene::chain::evaluation_error, 38002, "price multiplication underflow" ) - FC_DECLARE_DERIVED_EXCEPTION( price_multiplication_undefined, graphene::chain::evaluation_error, 38003, "price multiplication undefined product 0*inf" ) - */ + //GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( transfer_from_blind_operation ) + //GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_claim_fees_operation ) + //GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( bid_collateral_operation ) + //GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_claim_pool_operation ) + //GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_update_issuer_operation ) #define GRAPHENE_RECODE_EXC( cause_type, effect_type ) \ catch( const cause_type& e ) \ diff --git a/libraries/chain/include/graphene/chain/fba_accumulator_id.hpp b/libraries/chain/include/graphene/chain/fba_accumulator_id.hpp index 9bc0cf23..f0eefdbe 100644 --- a/libraries/chain/include/graphene/chain/fba_accumulator_id.hpp +++ b/libraries/chain/include/graphene/chain/fba_accumulator_id.hpp @@ -23,7 +23,7 @@ */ #pragma once -#include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/fba_object.hpp b/libraries/chain/include/graphene/chain/fba_object.hpp index 3d1e1be0..0927b235 100644 --- a/libraries/chain/include/graphene/chain/fba_object.hpp +++ b/libraries/chain/include/graphene/chain/fba_object.hpp @@ -23,7 +23,7 @@ */ #pragma once -#include +#include #include #include @@ -49,6 +49,8 @@ class fba_accumulator_object : public graphene::db::abstract_object< fba_accumul } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::fba_accumulator_object) + FC_REFLECT_DERIVED( graphene::chain::fba_accumulator_object, (graphene::db::object), (accumulated_fba_fees)(designated_asset) ) diff --git a/libraries/chain/include/graphene/chain/fork_database.hpp b/libraries/chain/include/graphene/chain/fork_database.hpp index 4007ca09..5e811e3d 100644 --- a/libraries/chain/include/graphene/chain/fork_database.hpp +++ b/libraries/chain/include/graphene/chain/fork_database.hpp @@ -22,7 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include +#include + +#include #include #include diff --git a/libraries/chain/include/graphene/chain/game_object.hpp b/libraries/chain/include/graphene/chain/game_object.hpp index abef1444..67a843bc 100644 --- a/libraries/chain/include/graphene/chain/game_object.hpp +++ b/libraries/chain/include/graphene/chain/game_object.hpp @@ -23,12 +23,17 @@ */ #pragma once -#include #include -#include + +#include + #include #include + #include + +#include + #include namespace graphene { namespace chain { @@ -159,6 +164,8 @@ namespace graphene { namespace chain { } } +MAP_OBJECT_ID_TO_TYPE(graphene::chain::game_object) + FC_REFLECT_ENUM(graphene::chain::game_state, (game_in_progress) (expecting_commit_moves) @@ -166,6 +173,6 @@ FC_REFLECT_ENUM(graphene::chain::game_state, (game_complete)) //FC_REFLECT_TYPENAME(graphene::chain::game_object) // manually serialized -FC_REFLECT(graphene::chain::game_object, (players)) +FC_REFLECT_DERIVED(graphene::chain::game_object, (graphene::db::object), (players)) diff --git a/libraries/chain/include/graphene/chain/genesis_state.hpp b/libraries/chain/include/graphene/chain/genesis_state.hpp index b2f76118..046f5e06 100644 --- a/libraries/chain/include/graphene/chain/genesis_state.hpp +++ b/libraries/chain/include/graphene/chain/genesis_state.hpp @@ -23,9 +23,9 @@ */ #pragma once -#include -#include -#include +#include +#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/get_config.hpp b/libraries/chain/include/graphene/chain/get_config.hpp index 4e49e688..adbdcee9 100644 --- a/libraries/chain/include/graphene/chain/get_config.hpp +++ b/libraries/chain/include/graphene/chain/get_config.hpp @@ -30,3 +30,4 @@ namespace graphene { namespace chain { fc::variant_object get_config(); } } // graphene::chain + diff --git a/libraries/chain/include/graphene/chain/global_betting_statistics_object.hpp b/libraries/chain/include/graphene/chain/global_betting_statistics_object.hpp index 6ded103a..e85d7472 100644 --- a/libraries/chain/include/graphene/chain/global_betting_statistics_object.hpp +++ b/libraries/chain/include/graphene/chain/global_betting_statistics_object.hpp @@ -23,7 +23,8 @@ */ #pragma once -#include +#include + #include #include @@ -49,4 +50,6 @@ typedef generic_index -#include -#include -#include -#include +#include +#include + +#include +#include + #include namespace graphene { namespace chain { @@ -89,8 +91,6 @@ namespace graphene { namespace chain { * every time a block is found it decreases by * RECENTLY_MISSED_COUNT_DECREMENT. It is * never less than 0. - * - * If the recently_missed_count hits 2*UNDO_HISTORY then no new blocks may be pushed. */ uint32_t recently_missed_count = 0; @@ -130,6 +130,9 @@ namespace graphene { namespace chain { }; }} +MAP_OBJECT_ID_TO_TYPE(graphene::chain::dynamic_global_property_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::global_property_object) + FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_object, (graphene::db::object), (head_block_number) (head_block_id) diff --git a/libraries/chain/include/graphene/chain/immutable_chain_parameters.hpp b/libraries/chain/include/graphene/chain/immutable_chain_parameters.hpp index f7128889..b0b62b48 100644 --- a/libraries/chain/include/graphene/chain/immutable_chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/immutable_chain_parameters.hpp @@ -24,7 +24,7 @@ #pragma once #include -#include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/impacted.hpp b/libraries/chain/include/graphene/chain/impacted.hpp index 3e070ce6..6bb43048 100644 --- a/libraries/chain/include/graphene/chain/impacted.hpp +++ b/libraries/chain/include/graphene/chain/impacted.hpp @@ -24,9 +24,9 @@ #pragma once #include -#include -#include -#include +#include +#include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/internal_exceptions.hpp b/libraries/chain/include/graphene/chain/internal_exceptions.hpp index 8a57ae23..4381c6de 100644 --- a/libraries/chain/include/graphene/chain/internal_exceptions.hpp +++ b/libraries/chain/include/graphene/chain/internal_exceptions.hpp @@ -23,11 +23,17 @@ */ #pragma once -#include #include #define GRAPHENE_DECLARE_INTERNAL_EXCEPTION( exc_name, seqnum, msg ) \ FC_DECLARE_DERIVED_EXCEPTION( \ + internal_ ## exc_name, \ + graphene::chain::internal_exception, \ + 3990000 + seqnum \ + ) + +#define GRAPHENE_IMPLEMENT_INTERNAL_EXCEPTION( exc_name, seqnum, msg ) \ + FC_IMPLEMENT_DERIVED_EXCEPTION( \ internal_ ## exc_name, \ graphene::chain::internal_exception, \ 3990000 + seqnum, \ @@ -36,7 +42,7 @@ namespace graphene { namespace chain { -FC_DECLARE_DERIVED_EXCEPTION( internal_exception, graphene::chain::chain_exception, 3990000, "internal exception" ) +FC_DECLARE_DERIVED_EXCEPTION( internal_exception, graphene::chain::chain_exception, 3990000 ) GRAPHENE_DECLARE_INTERNAL_EXCEPTION( verify_auth_max_auth_exceeded, 1, "Exceeds max authority fan-out" ) GRAPHENE_DECLARE_INTERNAL_EXCEPTION( verify_auth_account_not_found, 2, "Auth account not found" ) diff --git a/libraries/chain/include/graphene/chain/lottery_evaluator.hpp b/libraries/chain/include/graphene/chain/lottery_evaluator.hpp index 65c97d85..663d1321 100644 --- a/libraries/chain/include/graphene/chain/lottery_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/lottery_evaluator.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/market_evaluator.hpp b/libraries/chain/include/graphene/chain/market_evaluator.hpp index 9d653c07..778f012c 100644 --- a/libraries/chain/include/graphene/chain/market_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/market_evaluator.hpp @@ -23,7 +23,7 @@ */ #pragma once #include -#include +#include namespace graphene { namespace chain { @@ -31,9 +31,7 @@ namespace graphene { namespace chain { class asset_object; class asset_bitasset_data_object; class call_order_object; - struct call_order_update_operation; - struct limit_order_cancel_operation; - struct limit_order_create_operation; + class limit_order_object; class limit_order_create_evaluator : public evaluator { diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index 4bd3e048..3da60243 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -23,10 +23,10 @@ */ #pragma once -#include -#include #include #include +#include +#include #include @@ -65,7 +65,6 @@ class limit_order_object : public abstract_object asset amount_to_receive()const { return amount_for_sale() * sell_price; } }; -struct by_id; struct by_price; struct by_expiration; struct by_account; @@ -205,6 +204,10 @@ typedef generic_index + #include -#include +#include + +#include + #include #include + #include + +#include + #include namespace graphene { namespace chain { @@ -157,11 +164,13 @@ namespace graphene { namespace chain { } } +MAP_OBJECT_ID_TO_TYPE(graphene::chain::match_object) + FC_REFLECT_ENUM(graphene::chain::match_state, (waiting_on_previous_matches) (match_in_progress) (match_complete)) //FC_REFLECT_TYPENAME(graphene::chain::match_object) // manually serialized -FC_REFLECT(graphene::chain::match_object, (players)) +FC_REFLECT_DERIVED(graphene::chain::match_object, (graphene::db::object), (players)) diff --git a/libraries/chain/include/graphene/chain/nft_evaluator.hpp b/libraries/chain/include/graphene/chain/nft_evaluator.hpp index 0d0f5f51..a75cc44b 100644 --- a/libraries/chain/include/graphene/chain/nft_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/nft_evaluator.hpp @@ -2,8 +2,9 @@ #include #include -#include -#include + +#include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp b/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp index 0839cbbd..398fdcab 100644 --- a/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp @@ -1,8 +1,10 @@ #pragma once -#include + #include #include +#include + namespace graphene { namespace chain diff --git a/libraries/chain/include/graphene/chain/nft_object.hpp b/libraries/chain/include/graphene/chain/nft_object.hpp index fe026da5..037e5a64 100644 --- a/libraries/chain/include/graphene/chain/nft_object.hpp +++ b/libraries/chain/include/graphene/chain/nft_object.hpp @@ -1,5 +1,7 @@ #pragma once -#include + +#include + #include #include @@ -33,7 +35,7 @@ namespace graphene { namespace chain { { public: static const uint8_t space_id = protocol_ids; - static const uint8_t type_id = nft_metadata_type; + static const uint8_t type_id = nft_metadata_object_type; account_id_type owner; std::string name; @@ -177,6 +179,10 @@ namespace graphene { namespace chain { } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::nft_lottery_balance_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::nft_metadata_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::nft_object) + FC_REFLECT_DERIVED( graphene::chain::nft_lottery_balance_object, (graphene::db::object), (total_progressive_jackpot) (jackpot) diff --git a/libraries/chain/include/graphene/chain/offer_evaluator.hpp b/libraries/chain/include/graphene/chain/offer_evaluator.hpp index 46f7045b..5d779cd6 100644 --- a/libraries/chain/include/graphene/chain/offer_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/offer_evaluator.hpp @@ -1,7 +1,8 @@ -#include #include #include +#include + namespace graphene { namespace chain diff --git a/libraries/chain/include/graphene/chain/offer_object.hpp b/libraries/chain/include/graphene/chain/offer_object.hpp index fe176332..917a4f0f 100644 --- a/libraries/chain/include/graphene/chain/offer_object.hpp +++ b/libraries/chain/include/graphene/chain/offer_object.hpp @@ -1,5 +1,9 @@ #pragma once -#include + +#include + +#include + #include namespace graphene @@ -56,7 +60,8 @@ namespace graphene class offer_item_index : public secondary_index { public: - virtual void object_inserted(const object &obj) override; + virtual void object_loaded(const object &obj) override; + virtual void object_created(const object &obj) override; virtual void object_removed(const object &obj) override; virtual void about_to_modify(const object &before) override{}; virtual void object_modified(const object &after) override; @@ -99,6 +104,9 @@ namespace graphene } // namespace chain } // namespace graphene +MAP_OBJECT_ID_TO_TYPE(graphene::chain::offer_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::offer_history_object) + FC_REFLECT_DERIVED(graphene::chain::offer_object, (graphene::db::object), (issuer)(item_ids)(bidder)(bid_price)(minimum_price)( maximum_price)(buying_item)(offer_expiration_date)) diff --git a/libraries/chain/include/graphene/chain/operation_history_object.hpp b/libraries/chain/include/graphene/chain/operation_history_object.hpp index 89199472..b4538c60 100644 --- a/libraries/chain/include/graphene/chain/operation_history_object.hpp +++ b/libraries/chain/include/graphene/chain/operation_history_object.hpp @@ -23,82 +23,84 @@ */ #pragma once -#include +#include + +#include + #include #include namespace graphene { namespace chain { - /** - * @brief tracks the history of all logical operations on blockchain state - * @ingroup object - * @ingroup implementation - * - * All operations and virtual operations result in the creation of an - * operation_history_object that is maintained on disk as a stack. Each - * real or virtual operation is assigned a unique ID / sequence number that - * it can be referenced by. - * - * @note by default these objects are not tracked, the account_history_plugin must - * be loaded fore these objects to be maintained. - * - * @note this object is READ ONLY it can never be modified - */ - class operation_history_object : public abstract_object - { - public: - static const uint8_t space_id = protocol_ids; - static const uint8_t type_id = operation_history_object_type; +/** + * @brief tracks the history of all logical operations on blockchain state + * @ingroup object + * @ingroup implementation + * + * All operations and virtual operations result in the creation of an + * operation_history_object that is maintained on disk as a stack. Each + * real or virtual operation is assigned a unique ID / sequence number that + * it can be referenced by. + * + * @note by default these objects are not tracked, the account_history_plugin must + * be loaded fore these objects to be maintained. + * + * @note this object is READ ONLY it can never be modified + */ +class operation_history_object : public abstract_object +{ + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = operation_history_object_type; - operation_history_object( const operation& o ):op(o){} - operation_history_object(){} + operation_history_object( const operation& o ):op(o){} + operation_history_object(){} - operation op; - operation_result result; - /** the block that caused this operation */ - uint32_t block_num = 0; - /** the transaction in the block */ - uint16_t trx_in_block = 0; - /** the operation within the transaction */ - uint16_t op_in_trx = 0; - /** any virtual operations implied by operation in block */ - uint32_t virtual_op = 0; - }; + operation op; + operation_result result; + /** the block that caused this operation */ + uint32_t block_num = 0; + /** the transaction in the block */ + uint16_t trx_in_block = 0; + /** the operation within the transaction */ + uint16_t op_in_trx = 0; + /** any virtual operations implied by operation in block */ + uint32_t virtual_op = 0; +}; + +/** + * @brief a node in a linked list of operation_history_objects + * @ingroup implementation + * @ingroup object + * + * Account history is important for users and wallets even though it is + * not part of "core validation". Account history is maintained as + * a linked list stored on disk in a stack. Each account will point to the + * most recent account history object by ID. When a new operation relativent + * to that account is processed a new account history object is allcoated at + * the end of the stack and intialized to point to the prior object. + * + * This data is never accessed as part of chain validation and therefore + * can be kept on disk as a memory mapped file. Using a memory mapped file + * will help the operating system better manage / cache / page files and + * also accelerates load time. + * + * When the transaction history for a particular account is requested the + * linked list can be traversed with relatively effecient disk access because + * of the use of a memory mapped stack. + */ +class account_transaction_history_object : public abstract_object +{ + public: + static const uint8_t space_id = implementation_ids; + static const uint8_t type_id = impl_account_transaction_history_object_type; + account_id_type account; /// the account this operation applies to + operation_history_id_type operation_id; + uint32_t sequence = 0; /// the operation position within the given account + account_transaction_history_id_type next; +}; - /** - * @brief a node in a linked list of operation_history_objects - * @ingroup implementation - * @ingroup object - * - * Account history is important for users and wallets even though it is - * not part of "core validation". Account history is maintained as - * a linked list stored on disk in a stack. Each account will point to the - * most recent account history object by ID. When a new operation relativent - * to that account is processed a new account history object is allcoated at - * the end of the stack and intialized to point to the prior object. - * - * This data is never accessed as part of chain validation and therefore - * can be kept on disk as a memory mapped file. Using a memory mapped file - * will help the operating system better manage / cache / page files and - * also accelerates load time. - * - * When the transaction history for a particular account is requested the - * linked list can be traversed with relatively effecient disk access because - * of the use of a memory mapped stack. - */ - class account_transaction_history_object : public abstract_object - { - public: - static const uint8_t space_id = implementation_ids; - static const uint8_t type_id = impl_account_transaction_history_object_type; - account_id_type account; /// the account this operation applies to - operation_history_id_type operation_id; - uint32_t sequence = 0; /// the operation position within the given account - account_transaction_history_id_type next; - }; - - struct by_id; struct by_seq; struct by_op; struct by_opid; @@ -136,9 +138,11 @@ typedef multi_index_container< typedef generic_index account_transaction_history_index; - } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::operation_history_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::account_transaction_history_object) + FC_REFLECT_DERIVED( graphene::chain::operation_history_object, (graphene::chain::object), (op)(result)(block_num)(trx_in_block)(op_in_trx)(virtual_op) ) FC_REFLECT_DERIVED( graphene::chain::account_transaction_history_object, (graphene::chain::object), diff --git a/libraries/chain/include/graphene/chain/proposal_evaluator.hpp b/libraries/chain/include/graphene/chain/proposal_evaluator.hpp index 3e8ee15e..e4347df6 100644 --- a/libraries/chain/include/graphene/chain/proposal_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/proposal_evaluator.hpp @@ -23,7 +23,7 @@ */ #pragma once -#include +#include #include #include #include diff --git a/libraries/chain/include/graphene/chain/proposal_object.hpp b/libraries/chain/include/graphene/chain/proposal_object.hpp index d17d2c40..8809aea0 100644 --- a/libraries/chain/include/graphene/chain/proposal_object.hpp +++ b/libraries/chain/include/graphene/chain/proposal_object.hpp @@ -23,13 +23,16 @@ */ #pragma once -#include +#include #include #include #include namespace graphene { namespace chain { + using namespace graphene::protocol; + using namespace graphene::db; + class database; /** @@ -59,7 +62,7 @@ class proposal_object : public abstract_object }; /** - * @brief tracks all of the proposal objects that requrie approval of + * @brief tracks all of the proposal objects that require approval of * an individual account. * * @ingroup object @@ -72,7 +75,8 @@ class proposal_object : public abstract_object class required_approval_index : public secondary_index { public: - virtual void object_inserted( const object& obj ) override; + virtual void object_loaded( const object& obj ) override; + virtual void object_created( const object& obj ) override; virtual void object_removed( const object& obj ) override; virtual void about_to_modify( const object& before ) override{}; virtual void object_modified( const object& after ) override{}; @@ -94,6 +98,8 @@ typedef generic_index proposal_ } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::proposal_object) + FC_REFLECT_DERIVED( graphene::chain::proposal_object, (graphene::chain::object), (expiration_time)(review_period_time)(proposed_transaction)(required_active_approvals) (available_active_approvals)(required_owner_approvals)(available_owner_approvals) diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp deleted file mode 100644 index 321b08d9..00000000 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ /dev/null @@ -1,608 +0,0 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#define GRAPHENE_EXTERNAL_SERIALIZATION(ext, type) \ -namespace fc { \ - ext template void from_variant( const variant& v, type& vo, uint32_t max_depth ); \ - ext template void to_variant( const type& v, variant& vo, uint32_t max_depth ); \ -namespace raw { \ - ext template void pack< datastream, type >( datastream& s, const type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \ - ext template void pack< datastream, type >( datastream& s, const type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \ - ext template void unpack< datastream, type >( datastream& s, type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \ -} } // fc::raw - -#define FC_REFLECT_DERIVED_NO_TYPENAME( TYPE, INHERITS, MEMBERS ) \ -namespace fc { \ -template<> struct reflector {\ - typedef TYPE type; \ - typedef fc::true_type is_defined; \ - typedef fc::false_type is_enum; \ - enum member_count_enum { \ - local_member_count = 0 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_MEMBER_COUNT, +, MEMBERS ),\ - total_member_count = local_member_count BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_BASE_MEMBER_COUNT, +, INHERITS )\ - }; \ - FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \ -}; \ -} // fc - - -namespace graphene { namespace chain { - using namespace graphene::db; - - using std::map; - using std::vector; - using std::unordered_map; - using std::string; - using std::deque; - using std::shared_ptr; - using std::weak_ptr; - using std::unique_ptr; - using std::set; - using std::pair; - using std::enable_shared_from_this; - using std::tie; - using std::make_pair; - - using fc::smart_ref; - using fc::variant_object; - using fc::variant; - using fc::enum_type; - using fc::optional; - using fc::unsigned_int; - using fc::signed_int; - using fc::time_point_sec; - using fc::time_point; - using fc::safe; - using fc::flat_map; - using fc::flat_set; - using fc::static_variant; - using fc::ecc::range_proof_type; - using fc::ecc::range_proof_info; - using fc::ecc::commitment_type; - struct void_t{}; - - typedef fc::ecc::private_key private_key_type; - typedef fc::sha256 chain_id_type; - - enum asset_issuer_permission_flags - { - charge_market_fee = 0x01, /**< an issuer-specified percentage of all market trades in this asset is paid to the issuer */ - white_list = 0x02, /**< accounts must be whitelisted in order to hold this asset */ - override_authority = 0x04, /**< issuer may transfer asset back to himself */ - transfer_restricted = 0x08, /**< require the issuer to be one party to every transfer */ - disable_force_settle = 0x10, /**< disable force settling */ - global_settle = 0x20, /**< allow the bitasset issuer to force a global settling -- this may be set in permissions, but not flags */ - disable_confidential = 0x40, /**< allow the asset to be used with confidential transactions */ - witness_fed_asset = 0x80, /**< allow the asset to be fed by witnesses */ - committee_fed_asset = 0x100 /**< allow the asset to be fed by the committee */ - }; - const static uint32_t ASSET_ISSUER_PERMISSION_MASK = charge_market_fee|white_list|override_authority|transfer_restricted|disable_force_settle|global_settle|disable_confidential - |witness_fed_asset|committee_fed_asset; - const static uint32_t UIA_ASSET_ISSUER_PERMISSION_MASK = charge_market_fee|white_list|override_authority|transfer_restricted|disable_confidential; - - enum reserved_spaces - { - relative_protocol_ids = 0, - protocol_ids = 1, - implementation_ids = 2 - }; - - 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, - account_role_type, - son_object_type, - son_proposal_object_type, - son_wallet_object_type, - son_wallet_deposit_object_type, - son_wallet_withdraw_object_type, - sidechain_address_object_type, - sidechain_transaction_object_type, - random_number_object_type, - OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types - }; - - 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_asset_dividend_data_type, - impl_pending_dividend_payout_balance_for_holder_object_type, - impl_distributed_dividend_balance_data_type, - impl_betting_market_position_object_type, - impl_global_betting_statistics_object_type, - impl_lottery_balance_object_type, - impl_sweeps_vesting_balance_object_type, - impl_offer_history_object_type, - impl_son_statistics_object_type, - impl_son_schedule_object_type, - impl_nft_lottery_balance_object_type - }; - - //typedef fc::unsigned_int object_id_type; - //typedef uint64_t object_id_type; - class account_object; - class committee_member_object; - class witness_object; - class asset_object; - class force_settlement_object; - class limit_order_object; - class call_order_object; - class custom_object; - class proposal_object; - class operation_history_object; - class withdraw_permission_object; - class vesting_balance_object; - class worker_object; - class balance_object; - class blinded_balance_object; - class tournament_object; - class tournament_details_object; - class match_object; - class game_object; - class sport_object; - class event_group_object; - class event_object; - class betting_market_rules_object; - class betting_market_group_object; - class betting_market_object; - class bet_object; - class custom_permission_object; - class custom_account_authority_object; - class offer_object; - class nft_metadata_object; - class nft_object; - class account_role_object; - class son_object; - class son_proposal_object; - class son_wallet_object; - class son_wallet_deposit_object; - class son_wallet_withdraw_object; - class sidechain_address_object; - class sidechain_transaction_object; - class random_number_object; - - typedef object_id< protocol_ids, account_object_type, account_object> account_id_type; - typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type; - typedef object_id< protocol_ids, force_settlement_object_type, force_settlement_object> force_settlement_id_type; - typedef object_id< protocol_ids, committee_member_object_type, committee_member_object> committee_member_id_type; - typedef object_id< protocol_ids, witness_object_type, witness_object> witness_id_type; - typedef object_id< protocol_ids, limit_order_object_type, limit_order_object> limit_order_id_type; - typedef object_id< protocol_ids, call_order_object_type, call_order_object> call_order_id_type; - typedef object_id< protocol_ids, custom_object_type, custom_object> custom_id_type; - typedef object_id< protocol_ids, proposal_object_type, proposal_object> proposal_id_type; - typedef object_id< protocol_ids, operation_history_object_type, operation_history_object> operation_history_id_type; - typedef object_id< protocol_ids, withdraw_permission_object_type,withdraw_permission_object> withdraw_permission_id_type; - typedef object_id< protocol_ids, vesting_balance_object_type, vesting_balance_object> vesting_balance_id_type; - typedef object_id< protocol_ids, worker_object_type, worker_object> worker_id_type; - typedef object_id< protocol_ids, balance_object_type, balance_object> balance_id_type; - typedef object_id< protocol_ids, tournament_object_type, tournament_object> tournament_id_type; - typedef object_id< protocol_ids, tournament_details_object_type, tournament_details_object> tournament_details_id_type; - typedef object_id< protocol_ids, match_object_type, match_object> match_id_type; - typedef object_id< protocol_ids, game_object_type, game_object> game_id_type; - typedef object_id< protocol_ids, sport_object_type, sport_object> sport_id_type; - typedef object_id< protocol_ids, event_group_object_type, event_group_object> event_group_id_type; - typedef object_id< protocol_ids, event_object_type, event_object> event_id_type; - typedef object_id< protocol_ids, betting_market_rules_object_type, betting_market_rules_object> betting_market_rules_id_type; - typedef object_id< protocol_ids, betting_market_group_object_type, betting_market_group_object> betting_market_group_id_type; - typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type; - typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type; - typedef object_id< protocol_ids, custom_permission_object_type, custom_permission_object> custom_permission_id_type; - typedef object_id< protocol_ids, custom_account_authority_object_type, custom_account_authority_object> custom_account_authority_id_type; - typedef object_id< protocol_ids, offer_object_type, offer_object> offer_id_type; - typedef object_id< protocol_ids, nft_metadata_type, nft_metadata_object> nft_metadata_id_type; - typedef object_id< protocol_ids, nft_object_type, nft_object> nft_id_type; - typedef object_id< protocol_ids, account_role_type, account_role_object> account_role_id_type; - typedef object_id< protocol_ids, son_object_type, son_object> son_id_type; - typedef object_id< protocol_ids, son_proposal_object_type, son_proposal_object> son_proposal_id_type; - typedef object_id< protocol_ids, son_wallet_object_type, son_wallet_object> son_wallet_id_type; - typedef object_id< protocol_ids, son_wallet_deposit_object_type, son_wallet_deposit_object> son_wallet_deposit_id_type; - typedef object_id< protocol_ids, son_wallet_withdraw_object_type, son_wallet_withdraw_object> son_wallet_withdraw_id_type; - typedef object_id< protocol_ids, sidechain_address_object_type, sidechain_address_object> sidechain_address_id_type; - typedef object_id< protocol_ids, sidechain_transaction_object_type,sidechain_transaction_object> sidechain_transaction_id_type; - typedef object_id< protocol_ids, random_number_object_type, random_number_object> random_number_id_type; - - // implementation types - class global_property_object; - class dynamic_global_property_object; - class asset_dynamic_data_object; - class asset_bitasset_data_object; - class account_balance_object; - class account_statistics_object; - class transaction_object; - class block_summary_object; - class account_transaction_history_object; - class chain_property_object; - class witness_schedule_object; - class budget_record_object; - class special_authority_object; - class buyback_object; - class fba_accumulator_object; - class asset_dividend_data_object; - class pending_dividend_payout_balance_for_holder_object; - class betting_market_position_object; - class global_betting_statistics_object; - class lottery_balance_object; - class sweeps_vesting_balance_object; - class offer_history_object; - class nft_lottery_balance_object; - class son_statistics_object; - class son_schedule_object; - - typedef object_id< implementation_ids, impl_global_property_object_type, global_property_object> global_property_id_type; - typedef object_id< implementation_ids, impl_dynamic_global_property_object_type, dynamic_global_property_object> dynamic_global_property_id_type; - typedef object_id< implementation_ids, impl_asset_dynamic_data_type, asset_dynamic_data_object> asset_dynamic_data_id_type; - typedef object_id< implementation_ids, impl_asset_bitasset_data_type, asset_bitasset_data_object> asset_bitasset_data_id_type; - typedef object_id< implementation_ids, impl_asset_dividend_data_type, asset_dividend_data_object> asset_dividend_data_id_type; - typedef object_id< implementation_ids, - impl_pending_dividend_payout_balance_for_holder_object_type, - pending_dividend_payout_balance_for_holder_object> pending_dividend_payout_balance_for_holder_object_type; - typedef object_id< implementation_ids, impl_account_balance_object_type, account_balance_object> account_balance_id_type; - typedef object_id< implementation_ids, impl_account_statistics_object_type, account_statistics_object> account_statistics_id_type; - typedef object_id< implementation_ids, impl_transaction_object_type, transaction_object> transaction_obj_id_type; - typedef object_id< implementation_ids, impl_block_summary_object_type, block_summary_object> block_summary_id_type; - - typedef object_id< implementation_ids, - impl_account_transaction_history_object_type, - account_transaction_history_object> account_transaction_history_id_type; - typedef object_id< implementation_ids, impl_chain_property_object_type, chain_property_object> chain_property_id_type; - typedef object_id< implementation_ids, impl_witness_schedule_object_type, witness_schedule_object> witness_schedule_id_type; - typedef object_id< implementation_ids, impl_budget_record_object_type, budget_record_object > budget_record_id_type; - typedef object_id< implementation_ids, impl_blinded_balance_object_type, blinded_balance_object > blinded_balance_id_type; - typedef object_id< implementation_ids, impl_special_authority_object_type, special_authority_object > special_authority_id_type; - typedef object_id< implementation_ids, impl_buyback_object_type, buyback_object > buyback_id_type; - typedef object_id< implementation_ids, impl_fba_accumulator_object_type, fba_accumulator_object > fba_accumulator_id_type; - typedef object_id< implementation_ids, impl_betting_market_position_object_type, betting_market_position_object > betting_market_position_id_type; - typedef object_id< implementation_ids, impl_global_betting_statistics_object_type, global_betting_statistics_object > global_betting_statistics_id_type; - typedef object_id< implementation_ids, impl_lottery_balance_object_type, lottery_balance_object > lottery_balance_id_type; - typedef object_id< implementation_ids, impl_sweeps_vesting_balance_object_type, sweeps_vesting_balance_object> sweeps_vesting_balance_id_type; - typedef object_id< implementation_ids, impl_offer_history_object_type, offer_history_object> offer_history_id_type; - typedef object_id< implementation_ids, impl_nft_lottery_balance_object_type, nft_lottery_balance_object> nft_lottery_balance_id_type; - typedef object_id< implementation_ids, impl_son_statistics_object_type, son_statistics_object > son_statistics_id_type; - typedef object_id< implementation_ids, impl_son_schedule_object_type, son_schedule_object> son_schedule_id_type; - - typedef fc::array symbol_type; - typedef fc::ripemd160 block_id_type; - typedef fc::ripemd160 checksum_type; - typedef fc::ripemd160 transaction_id_type; - typedef fc::sha256 digest_type; - typedef fc::ecc::compact_signature signature_type; - typedef safe share_type; - typedef fc::ripemd160 secret_hash_type; - typedef uint16_t weight_type; - - struct public_key_type - { - struct binary_key - { - binary_key() {} - uint32_t check = 0; - fc::ecc::public_key_data data; - }; - fc::ecc::public_key_data key_data; - public_key_type(); - public_key_type( const fc::ecc::public_key_data& data ); - public_key_type( const fc::ecc::public_key& pubkey ); - explicit public_key_type( const std::string& base58str ); - operator fc::ecc::public_key_data() const; - operator fc::ecc::public_key() const; - explicit operator std::string() const; - friend bool operator == ( const public_key_type& p1, const fc::ecc::public_key& p2); - friend bool operator == ( const public_key_type& p1, const public_key_type& p2); - friend bool operator != ( const public_key_type& p1, const public_key_type& p2); - // TODO: This is temporary for testing - bool is_valid_v1( const std::string& base58str ); - bool is_valid_muse( const std::string& base58str ); - }; - - struct extended_public_key_type - { - struct binary_key - { - binary_key() {} - uint32_t check = 0; - fc::ecc::extended_key_data data; - }; - - fc::ecc::extended_key_data key_data; - - extended_public_key_type(); - extended_public_key_type( const fc::ecc::extended_key_data& data ); - extended_public_key_type( const fc::ecc::extended_public_key& extpubkey ); - explicit extended_public_key_type( const std::string& base58str ); - operator fc::ecc::extended_public_key() const; - explicit operator std::string() const; - friend bool operator == ( const extended_public_key_type& p1, const fc::ecc::extended_public_key& p2); - friend bool operator == ( const extended_public_key_type& p1, const extended_public_key_type& p2); - friend bool operator != ( const extended_public_key_type& p1, const extended_public_key_type& p2); - }; - - struct extended_private_key_type - { - struct binary_key - { - binary_key() {} - uint32_t check = 0; - fc::ecc::extended_key_data data; - }; - - fc::ecc::extended_key_data key_data; - - extended_private_key_type(); - extended_private_key_type( const fc::ecc::extended_key_data& data ); - extended_private_key_type( const fc::ecc::extended_private_key& extprivkey ); - explicit extended_private_key_type( const std::string& base58str ); - operator fc::ecc::extended_private_key() const; - explicit operator std::string() const; - friend bool operator == ( const extended_private_key_type& p1, const fc::ecc::extended_private_key& p2); - friend bool operator == ( const extended_private_key_type& p1, const extended_private_key_type& p2); - friend bool operator != ( const extended_private_key_type& p1, const extended_private_key_type& p2); - }; - - typedef flat_map internationalized_string_type; - - typedef uint32_t bet_multiplier_type; -} } // graphene::chain - -namespace fc -{ - void to_variant( const graphene::chain::public_key_type& var, fc::variant& vo, uint32_t max_depth = 2 ); - void from_variant( const fc::variant& var, graphene::chain::public_key_type& vo, uint32_t max_depth = 2 ); - void to_variant( const graphene::chain::extended_public_key_type& var, fc::variant& vo, uint32_t max_depth = 2 ); - void from_variant( const fc::variant& var, graphene::chain::extended_public_key_type& vo, uint32_t max_depth = 2 ); - void to_variant( const graphene::chain::extended_private_key_type& var, fc::variant& vo, uint32_t max_depth = 2 ); - void from_variant( const fc::variant& var, graphene::chain::extended_private_key_type& vo, uint32_t max_depth = 2 ); -} - -FC_REFLECT( graphene::chain::public_key_type, (key_data) ) -FC_REFLECT( graphene::chain::public_key_type::binary_key, (data)(check) ) -FC_REFLECT( graphene::chain::extended_public_key_type, (key_data) ) -FC_REFLECT( graphene::chain::extended_public_key_type::binary_key, (check)(data) ) -FC_REFLECT( graphene::chain::extended_private_key_type, (key_data) ) -FC_REFLECT( graphene::chain::extended_private_key_type::binary_key, (check)(data) ) - -FC_REFLECT_ENUM( graphene::chain::object_type, - (null_object_type) - (base_object_type) - (account_object_type) - (force_settlement_object_type) - (asset_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) - (account_role_type) - (son_object_type) - (son_proposal_object_type) - (son_wallet_object_type) - (son_wallet_deposit_object_type) - (son_wallet_withdraw_object_type) - (sidechain_address_object_type) - (sidechain_transaction_object_type) - (random_number_object_type) - (OBJECT_TYPE_COUNT) - ) -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_asset_dividend_data_type) - (impl_pending_dividend_payout_balance_for_holder_object_type) - (impl_distributed_dividend_balance_data_type) - (impl_betting_market_position_object_type) - (impl_global_betting_statistics_object_type) - (impl_lottery_balance_object_type) - (impl_sweeps_vesting_balance_object_type) - (impl_offer_history_object_type) - (impl_son_statistics_object_type) - (impl_son_schedule_object_type) - (impl_nft_lottery_balance_object_type) - ) - -FC_REFLECT_TYPENAME( graphene::chain::share_type ) - -FC_REFLECT_TYPENAME( graphene::chain::account_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::asset_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::force_settlement_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::committee_member_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::witness_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::limit_order_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::call_order_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::custom_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::proposal_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::operation_history_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::withdraw_permission_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::vesting_balance_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::worker_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::balance_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::sport_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::event_group_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::event_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::betting_market_rules_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::betting_market_group_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::betting_market_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::bet_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::tournament_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::offer_id_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::betting_market_position_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::custom_permission_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::custom_account_authority_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::offer_history_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::nft_metadata_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::nft_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::account_role_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::nft_lottery_balance_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::son_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::son_proposal_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::son_wallet_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::son_wallet_deposit_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::son_wallet_withdraw_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::sidechain_address_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::sidechain_transaction_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::random_number_id_type ) - -FC_REFLECT( graphene::chain::void_t, ) - -FC_REFLECT_ENUM( graphene::chain::asset_issuer_permission_flags, - (charge_market_fee) - (white_list) - (transfer_restricted) - (override_authority) - (disable_force_settle) - (global_settle) - (disable_confidential) - (witness_fed_asset) - (committee_fed_asset) - ) diff --git a/libraries/chain/include/graphene/chain/random_number_evaluator.hpp b/libraries/chain/include/graphene/chain/random_number_evaluator.hpp index a26b9f3e..5146a522 100644 --- a/libraries/chain/include/graphene/chain/random_number_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/random_number_evaluator.hpp @@ -1,8 +1,9 @@ #pragma once #include #include -#include -#include +#include + +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/random_number_object.hpp b/libraries/chain/include/graphene/chain/random_number_object.hpp index 3613d7a1..eb8c528a 100644 --- a/libraries/chain/include/graphene/chain/random_number_object.hpp +++ b/libraries/chain/include/graphene/chain/random_number_object.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace graphene { namespace chain { using namespace graphene::db; diff --git a/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp b/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp index 7e2e8c7c..caba1d3c 100644 --- a/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp +++ b/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include #include namespace graphene diff --git a/libraries/chain/include/graphene/chain/rock_paper_scissors.hpp b/libraries/chain/include/graphene/chain/rock_paper_scissors.hpp index 23015e3e..f2b6c382 100644 --- a/libraries/chain/include/graphene/chain/rock_paper_scissors.hpp +++ b/libraries/chain/include/graphene/chain/rock_paper_scissors.hpp @@ -26,11 +26,14 @@ #include +#include + +#include + #include #include #include #include -#include namespace graphene { namespace chain { struct rock_paper_scissors_game_details diff --git a/libraries/chain/include/graphene/chain/sidechain_address_evaluator.hpp b/libraries/chain/include/graphene/chain/sidechain_address_evaluator.hpp index 82bfcf1a..1ff564b6 100644 --- a/libraries/chain/include/graphene/chain/sidechain_address_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_address_evaluator.hpp @@ -1,6 +1,7 @@ #pragma once #include -#include + +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp index b8aa07c6..6e58c8c6 100644 --- a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp @@ -1,13 +1,15 @@ #pragma once -#include #include #include -#include +#include +#include + #include namespace graphene { namespace chain { using namespace graphene::db; + using namespace graphene::protocol; /** * @class sidechain_address_object @@ -86,6 +88,8 @@ namespace graphene { namespace chain { } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::sidechain_address_object) + FC_REFLECT_DERIVED( graphene::chain::sidechain_address_object, (graphene::db::object), (sidechain_address_account) (sidechain) (deposit_public_key) (deposit_address) (deposit_address_data) diff --git a/libraries/chain/include/graphene/chain/sidechain_transaction_evaluator.hpp b/libraries/chain/include/graphene/chain/sidechain_transaction_evaluator.hpp index 702788ff..66b817e9 100644 --- a/libraries/chain/include/graphene/chain/sidechain_transaction_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_transaction_evaluator.hpp @@ -1,6 +1,7 @@ #pragma once #include -#include + +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp b/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp index 30a0dd5e..9df2180e 100644 --- a/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp @@ -1,11 +1,13 @@ #pragma once +#include +#include +#include + #include -#include -#include -#include namespace graphene { namespace chain { using namespace graphene::db; + using namespace graphene::protocol; enum class sidechain_transaction_status { invalid, @@ -70,6 +72,8 @@ FC_REFLECT_ENUM( graphene::chain::sidechain_transaction_status, (sent) (settled) ) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::sidechain_transaction_object) + FC_REFLECT_DERIVED( graphene::chain::sidechain_transaction_object, (graphene::db::object ), (timestamp) (sidechain) diff --git a/libraries/chain/include/graphene/chain/son_evaluator.hpp b/libraries/chain/include/graphene/chain/son_evaluator.hpp index c3f1ac49..9ac66e49 100644 --- a/libraries/chain/include/graphene/chain/son_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/son_evaluator.hpp @@ -1,6 +1,7 @@ #pragma once +#include + #include -#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/son_object.hpp b/libraries/chain/include/graphene/chain/son_object.hpp index d0b74e79..afc68abe 100644 --- a/libraries/chain/include/graphene/chain/son_object.hpp +++ b/libraries/chain/include/graphene/chain/son_object.hpp @@ -1,8 +1,9 @@ #pragma once -#include #include #include -#include + +#include +#include namespace graphene { namespace chain { using namespace graphene::db; @@ -113,6 +114,9 @@ namespace graphene { namespace chain { } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::son_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::son_statistics_object) + FC_REFLECT_ENUM(graphene::chain::son_status, (inactive)(active)(request_maintenance)(in_maintenance)(deregistered) ) FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object), diff --git a/libraries/chain/include/graphene/chain/son_proposal_object.hpp b/libraries/chain/include/graphene/chain/son_proposal_object.hpp index 7b1674b8..92ecf4a5 100644 --- a/libraries/chain/include/graphene/chain/son_proposal_object.hpp +++ b/libraries/chain/include/graphene/chain/son_proposal_object.hpp @@ -1,9 +1,10 @@ #pragma once -#include #include #include +#include + namespace graphene { namespace chain { enum class son_proposal_type @@ -37,6 +38,8 @@ using son_proposal_index = generic_index -#include -#include +#include +#include +#include namespace graphene { namespace chain { using namespace graphene::db; + using namespace graphene::protocol; /** * @class son_wallet_deposit_object @@ -61,6 +62,8 @@ namespace graphene { namespace chain { using son_wallet_deposit_index = generic_index; } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::son_wallet_deposit_object) + FC_REFLECT_DERIVED( graphene::chain::son_wallet_deposit_object, (graphene::db::object), (timestamp) (block_num) (sidechain) (sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_currency) (sidechain_amount) diff --git a/libraries/chain/include/graphene/chain/son_wallet_evaluator.hpp b/libraries/chain/include/graphene/chain/son_wallet_evaluator.hpp index 78e8655f..6856c2b8 100644 --- a/libraries/chain/include/graphene/chain/son_wallet_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/son_wallet_evaluator.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/son_wallet_object.hpp b/libraries/chain/include/graphene/chain/son_wallet_object.hpp index 315def33..9395aecf 100644 --- a/libraries/chain/include/graphene/chain/son_wallet_object.hpp +++ b/libraries/chain/include/graphene/chain/son_wallet_object.hpp @@ -1,10 +1,17 @@ #pragma once -#include -#include -#include +#include +#include +#include +#include +#include + +#include + namespace graphene { namespace chain { + using namespace graphene::protocol; using namespace graphene::db; + using namespace boost::multi_index; /** * @class son_wallet_object @@ -43,5 +50,7 @@ namespace graphene { namespace chain { using son_wallet_index = generic_index; } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::son_wallet_object) + FC_REFLECT_DERIVED( graphene::chain::son_wallet_object, (graphene::db::object), (valid_from) (expires) (addresses) (sons) ) diff --git a/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp b/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp index d65f5cab..9f830c03 100644 --- a/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp +++ b/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp @@ -1,10 +1,11 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace graphene { namespace chain { using namespace graphene::db; + using namespace graphene::protocol; /** * @class son_wallet_withdraw_object @@ -60,6 +61,8 @@ namespace graphene { namespace chain { using son_wallet_withdraw_index = generic_index; } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::son_wallet_withdraw_object) + FC_REFLECT_DERIVED( graphene::chain::son_wallet_withdraw_object, (graphene::db::object), (timestamp) (block_num) (sidechain) (peerplays_uid) (peerplays_transaction_id) (peerplays_from) (peerplays_asset) diff --git a/libraries/chain/include/graphene/chain/special_authority.hpp b/libraries/chain/include/graphene/chain/special_authority.hpp index f091f736..80cfab8d 100644 --- a/libraries/chain/include/graphene/chain/special_authority.hpp +++ b/libraries/chain/include/graphene/chain/special_authority.hpp @@ -23,11 +23,12 @@ */ #pragma once -#include +#include namespace graphene { namespace chain { class database; +using namespace graphene::protocol; void evaluate_special_authority( const database& db, const special_authority& auth ); diff --git a/libraries/chain/include/graphene/chain/special_authority_object.hpp b/libraries/chain/include/graphene/chain/special_authority_object.hpp index 75093f3a..d1d999ee 100644 --- a/libraries/chain/include/graphene/chain/special_authority_object.hpp +++ b/libraries/chain/include/graphene/chain/special_authority_object.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include @@ -63,6 +63,8 @@ typedef generic_index< special_authority_object, special_authority_multi_index_t } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::special_authority_object) + FC_REFLECT_DERIVED( graphene::chain::special_authority_object, (graphene::db::object), diff --git a/libraries/chain/include/graphene/chain/sport_evaluator.hpp b/libraries/chain/include/graphene/chain/sport_evaluator.hpp index 4724e795..0f91305d 100644 --- a/libraries/chain/include/graphene/chain/sport_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/sport_evaluator.hpp @@ -23,7 +23,7 @@ */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/sport_object.hpp b/libraries/chain/include/graphene/chain/sport_object.hpp index 4f3139d8..3da135b5 100644 --- a/libraries/chain/include/graphene/chain/sport_object.hpp +++ b/libraries/chain/include/graphene/chain/sport_object.hpp @@ -23,7 +23,8 @@ */ #pragma once -#include +#include + #include #include @@ -48,4 +49,6 @@ typedef multi_index_container< typedef generic_index sport_object_index; } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::sport_object) + FC_REFLECT_DERIVED( graphene::chain::sport_object, (graphene::db::object), (name) ) diff --git a/libraries/chain/include/graphene/chain/tournament_evaluator.hpp b/libraries/chain/include/graphene/chain/tournament_evaluator.hpp index 18a0140d..9cce918d 100644 --- a/libraries/chain/include/graphene/chain/tournament_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/tournament_evaluator.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/tournament_object.hpp b/libraries/chain/include/graphene/chain/tournament_object.hpp index 140770e2..51964f60 100644 --- a/libraries/chain/include/graphene/chain/tournament_object.hpp +++ b/libraries/chain/include/graphene/chain/tournament_object.hpp @@ -1,12 +1,19 @@ #pragma once -#include + +#include #include -#include +#include + +#include + #include #include + #include #include +#include + namespace graphene { namespace chain { class tournament_object; } } @@ -217,7 +224,8 @@ namespace graphene { namespace chain { class tournament_players_index : public secondary_index { public: - virtual void object_inserted( const object& obj ) override; + virtual void object_loaded( const object& obj ) override; + virtual void object_created( const object& obj ) override; virtual void object_removed( const object& obj ) override; virtual void about_to_modify( const object& before ) override; virtual void object_modified( const object& after ) override; @@ -234,6 +242,9 @@ namespace graphene { namespace chain { } } +MAP_OBJECT_ID_TO_TYPE(graphene::chain::tournament_details_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::tournament_object) + FC_REFLECT_DERIVED(graphene::chain::tournament_details_object, (graphene::db::object), (tournament_id) (registered_players) @@ -241,7 +252,7 @@ FC_REFLECT_DERIVED(graphene::chain::tournament_details_object, (graphene::db::ob (players_payers) (matches)) //FC_REFLECT_TYPENAME(graphene::chain::tournament_object) // manually serialized -FC_REFLECT(graphene::chain::tournament_object, (creator)) +FC_REFLECT_DERIVED(graphene::chain::tournament_object, (graphene::db::object), (creator)) FC_REFLECT_ENUM(graphene::chain::tournament_state, (accepting_registrations) (awaiting_start) diff --git a/libraries/chain/include/graphene/chain/transaction_evaluation_state.hpp b/libraries/chain/include/graphene/chain/transaction_evaluation_state.hpp index 5ffb4bb7..c6daeaa4 100644 --- a/libraries/chain/include/graphene/chain/transaction_evaluation_state.hpp +++ b/libraries/chain/include/graphene/chain/transaction_evaluation_state.hpp @@ -22,11 +22,16 @@ * THE SOFTWARE. */ #pragma once -#include +#include -namespace graphene { namespace chain { +#include + +namespace graphene { +namespace protocol { struct signed_transaction; } +namespace chain { class database; - struct signed_transaction; + using protocol::signed_transaction; + using protocol::operation_result; /** * Place holder for state tracked while processing a transaction. This class provides helper methods that are @@ -40,7 +45,7 @@ namespace graphene { namespace chain { database& db()const { assert( _db ); return *_db; } - vector operation_results; + std::vector operation_results; const signed_transaction* _trx = nullptr; database* _db = nullptr; diff --git a/libraries/chain/include/graphene/chain/transaction_object.hpp b/libraries/chain/include/graphene/chain/transaction_history_object.hpp similarity index 68% rename from libraries/chain/include/graphene/chain/transaction_object.hpp rename to libraries/chain/include/graphene/chain/transaction_history_object.hpp index aaaa31f1..185ab2ac 100644 --- a/libraries/chain/include/graphene/chain/transaction_object.hpp +++ b/libraries/chain/include/graphene/chain/transaction_history_object.hpp @@ -23,7 +23,10 @@ */ #pragma once -#include +#include + +#include + #include #include @@ -39,14 +42,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; @@ -55,20 +58,24 @@ namespace graphene { namespace chain { }; struct by_expiration; - struct by_id; 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; } } -FC_REFLECT_DERIVED( graphene::chain::transaction_object, (graphene::db::object), (trx)(trx_id) ) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::transaction_history_object) + +FC_REFLECT_DERIVED( graphene::chain::transaction_history_object, (graphene::db::object), (trx)(trx_id) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transaction_history_object ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transaction_object ) diff --git a/libraries/chain/include/graphene/chain/transfer_evaluator.hpp b/libraries/chain/include/graphene/chain/transfer_evaluator.hpp index 900ab074..6c2bc7ee 100644 --- a/libraries/chain/include/graphene/chain/transfer_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/transfer_evaluator.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/types.hpp b/libraries/chain/include/graphene/chain/types.hpp new file mode 100644 index 00000000..bf3d2e4d --- /dev/null +++ b/libraries/chain/include/graphene/chain/types.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include + +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) + (asset_dividend_data) + (pending_dividend_payout_balance_for_holder) + (total_distributed_dividend_balance) + (betting_market_position) + (global_betting_statistics) + (lottery_balance) + (sweeps_vesting_balance) + (offer_history) + (son_statistics) + (son_schedule) + (nft_lottery_balance)) diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 998950bf..b5359e8e 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -23,9 +23,9 @@ */ #pragma once -#include -#include +#include +#include #include #include @@ -37,6 +37,7 @@ namespace graphene { namespace chain { using namespace graphene::db; + using namespace graphene::protocol; struct vesting_policy_context { @@ -89,11 +90,11 @@ namespace graphene { namespace chain { */ struct cdd_vesting_policy { - uint32_t vesting_seconds = 0; - fc::uint128_t coin_seconds_earned; + uint32_t vesting_seconds = 0; + fc::uint128_t coin_seconds_earned; /** while coindays may accrue over time, none may be claimed before first_claim date */ - fc::time_point_sec start_claim; - fc::time_point_sec coin_seconds_earned_last_update; + fc::time_point_sec start_claim; + fc::time_point_sec coin_seconds_earned_last_update; /** * Compute coin_seconds_earned. Used to @@ -244,6 +245,8 @@ namespace graphene { namespace chain { } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::vesting_balance_object) + FC_REFLECT(graphene::chain::linear_vesting_policy, (begin_timestamp) (vesting_cliff_seconds) diff --git a/libraries/chain/include/graphene/chain/vote_count.hpp b/libraries/chain/include/graphene/chain/vote_count.hpp index ab2f3612..17ea2508 100644 --- a/libraries/chain/include/graphene/chain/vote_count.hpp +++ b/libraries/chain/include/graphene/chain/vote_count.hpp @@ -24,7 +24,7 @@ #pragma once -#include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp b/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp index a6fee0c5..824d2f94 100644 --- a/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp +++ b/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp @@ -22,8 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include +#include #include namespace graphene { namespace chain { @@ -105,6 +106,8 @@ namespace graphene { namespace chain { } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::withdraw_permission_object) + FC_REFLECT_DERIVED( graphene::chain::withdraw_permission_object, (graphene::db::object), (withdraw_from_account) (authorized_account) diff --git a/libraries/chain/include/graphene/chain/witness_object.hpp b/libraries/chain/include/graphene/chain/witness_object.hpp index 7928b46e..2647dcd8 100644 --- a/libraries/chain/include/graphene/chain/witness_object.hpp +++ b/libraries/chain/include/graphene/chain/witness_object.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include @@ -70,6 +70,8 @@ namespace graphene { namespace chain { using witness_index = generic_index; } } // graphene::chain +MAP_OBJECT_ID_TO_TYPE(graphene::chain::witness_object) + FC_REFLECT_DERIVED( graphene::chain::witness_object, (graphene::db::object), (witness_account) (last_aslot) diff --git a/libraries/chain/include/graphene/chain/witness_schedule_object.hpp b/libraries/chain/include/graphene/chain/witness_schedule_object.hpp index 2eff563f..fd9e0f8d 100644 --- a/libraries/chain/include/graphene/chain/witness_schedule_object.hpp +++ b/libraries/chain/include/graphene/chain/witness_schedule_object.hpp @@ -22,11 +22,23 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include #include #include +#include + +#include + +#include +#include + +#include + +#include + +#include +#include + +#include namespace graphene { namespace chain { @@ -81,13 +93,13 @@ class witness_schedule_object : public graphene::db::abstract_object rng_seed; + std::array< char, sizeof(secret_hash_type) > rng_seed = {}; /** * Not necessary for consensus, but used for figuring out the participation rate. * The nth bit is 0 if the nth slot was unfilled, else it is 1. */ - fc::uint128 recent_slots_filled; + fc::uint128_t recent_slots_filled; }; class son_schedule_object : public graphene::db::abstract_object @@ -101,17 +113,19 @@ class son_schedule_object : public graphene::db::abstract_object rng_seed; + std::array< char, sizeof(secret_hash_type) > rng_seed = {}; /** * Not necessary for consensus, but used for figuring out the participation rate. * The nth bit is 0 if the nth slot was unfilled, else it is 1. */ - fc::uint128 recent_slots_filled; + fc::uint128_t recent_slots_filled; }; } } +MAP_OBJECT_ID_TO_TYPE(graphene::chain::witness_schedule_object) +MAP_OBJECT_ID_TO_TYPE(graphene::chain::son_schedule_object) FC_REFLECT( graphene::chain::witness_scheduler, (_turns) diff --git a/libraries/chain/include/graphene/chain/worker_object.hpp b/libraries/chain/include/graphene/chain/worker_object.hpp index 5e23f0b8..ec14631c 100644 --- a/libraries/chain/include/graphene/chain/worker_object.hpp +++ b/libraries/chain/include/graphene/chain/worker_object.hpp @@ -22,11 +22,12 @@ * THE SOFTWARE. */ #pragma once -#include #include -#include +#include +#include namespace graphene { namespace chain { +class database; /** * @defgroup worker_types Implementations of the various worker types in the system @@ -159,6 +160,8 @@ using worker_index = generic_index #include -#include +#include #include diff --git a/libraries/chain/nft_evaluator.cpp b/libraries/chain/nft_evaluator.cpp index eedbd5cc..e46c99bb 100644 --- a/libraries/chain/nft_evaluator.cpp +++ b/libraries/chain/nft_evaluator.cpp @@ -1,6 +1,10 @@ #include + +#include +#include +#include + #include -#include #include #include diff --git a/libraries/chain/nft_lottery_evaluator.cpp b/libraries/chain/nft_lottery_evaluator.cpp index 794616cf..64c32eca 100644 --- a/libraries/chain/nft_lottery_evaluator.cpp +++ b/libraries/chain/nft_lottery_evaluator.cpp @@ -1,9 +1,10 @@ #include #include -#include #include #include +#include + namespace graphene { namespace chain @@ -142,4 +143,4 @@ namespace graphene FC_CAPTURE_AND_RETHROW((op)) } } // namespace chain -} // namespace graphene \ No newline at end of file +} // namespace graphene diff --git a/libraries/chain/offer_evaluator.cpp b/libraries/chain/offer_evaluator.cpp index 1b887466..12f3feed 100644 --- a/libraries/chain/offer_evaluator.cpp +++ b/libraries/chain/offer_evaluator.cpp @@ -1,12 +1,14 @@ +#include + #include #include #include #include -#include #include #include #include #include + #include namespace graphene @@ -94,7 +96,6 @@ namespace graphene auto now = d.head_block_time(); FC_ASSERT(now >= HARDFORK_NFT_TIME, "Not allowed until NFT HF"); const auto &offer = op.offer_id(d); - op.bidder(d); for (const auto &item : offer.item_ids) { const auto &nft_obj = item(d); diff --git a/libraries/chain/offer_object.cpp b/libraries/chain/offer_object.cpp index 35ac47d2..795648f3 100644 --- a/libraries/chain/offer_object.cpp +++ b/libraries/chain/offer_object.cpp @@ -6,7 +6,12 @@ namespace graphene namespace chain { - void offer_item_index::object_inserted(const object &obj) + void offer_item_index::object_loaded(const object &obj) + { + object_created(obj); + } + + void offer_item_index::object_created(const object &obj) { assert(dynamic_cast(&obj)); const offer_object &oo = static_cast(obj); @@ -47,4 +52,4 @@ namespace graphene } } // namespace chain -} // namespace graphene \ No newline at end of file +} // namespace graphene diff --git a/libraries/chain/proposal_evaluator.cpp b/libraries/chain/proposal_evaluator.cpp index ac8ef601..de35a02e 100644 --- a/libraries/chain/proposal_evaluator.cpp +++ b/libraries/chain/proposal_evaluator.cpp @@ -26,9 +26,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -402,7 +402,7 @@ void_result proposal_update_evaluator::do_apply(const proposal_update_operation& // Potential optimization: if _executed_proposal is true, we can skip the modify step and make push_proposal skip // signature checks. This isn't done now because I just wrote all the proposals code, and I'm not yet 100% sure the // required approvals are sufficient to authorize the transaction. - d.modify(*_proposal, [&o, &d](proposal_object& p) { + d.modify(*_proposal, [&o](proposal_object& p) { p.available_active_approvals.insert(o.active_approvals_to_add.begin(), o.active_approvals_to_add.end()); p.available_owner_approvals.insert(o.owner_approvals_to_add.begin(), o.owner_approvals_to_add.end()); for( account_id_type id : o.active_approvals_to_remove ) diff --git a/libraries/chain/proposal_object.cpp b/libraries/chain/proposal_object.cpp index 662c700a..2841daa9 100644 --- a/libraries/chain/proposal_object.cpp +++ b/libraries/chain/proposal_object.cpp @@ -52,7 +52,12 @@ bool proposal_object::is_authorized_to_execute( database& db ) const return true; } -void required_approval_index::object_inserted( const object& obj ) +void required_approval_index::object_loaded( const object& obj ) +{ + object_created(obj); +} + +void required_approval_index::object_created( const object& obj ) { assert( dynamic_cast(&obj) ); const proposal_object& p = static_cast(obj); diff --git a/libraries/chain/protocol/types.cpp b/libraries/chain/protocol/types.cpp deleted file mode 100644 index b7cac207..00000000 --- a/libraries/chain/protocol/types.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include -#include - -#include -#include -#include -#include - -namespace graphene { namespace chain { - - public_key_type::public_key_type():key_data(){}; - - public_key_type::public_key_type( const fc::ecc::public_key_data& data ) - :key_data( data ) {}; - - public_key_type::public_key_type( const fc::ecc::public_key& pubkey ) - :key_data( pubkey ) {}; - - public_key_type::public_key_type( const std::string& base58str ) - { - // TODO: Refactor syntactic checks into static is_valid() - // to make public_key_type API more similar to address API - std::string prefix( GRAPHENE_ADDRESS_PREFIX ); - - // TODO: This is temporary for testing - try - { - if( is_valid_v1( base58str ) ) - prefix = std::string( "BTS" ); - } - catch( ... ) - { - } - - try - { - if( is_valid_muse( base58str ) ) - prefix = std::string( "MUSE" ); - } - catch( ... ) - { - } - - const size_t prefix_len = prefix.size(); - FC_ASSERT( base58str.size() > prefix_len ); - FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); - auto bin = fc::from_base58( base58str.substr( prefix_len ) ); - auto bin_key = fc::raw::unpack(bin); - key_data = bin_key.data; - FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check ); - }; - - bool public_key_type::is_valid_muse( const std::string& base58str ) - { - std::string prefix( "MUSE" ); - - const size_t prefix_len = prefix.size(); - FC_ASSERT( base58str.size() > prefix_len ); - FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); - auto bin = fc::from_base58( base58str.substr( prefix_len ) ); - auto bin_key = fc::raw::unpack(bin); - key_data = bin_key.data; - FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check ); - return true; - } - - // TODO: This is temporary for testing - bool public_key_type::is_valid_v1( const std::string& base58str ) - { - std::string prefix( "BTS" ); - const size_t prefix_len = prefix.size(); - FC_ASSERT( base58str.size() > prefix_len ); - FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); - auto bin = fc::from_base58( base58str.substr( prefix_len ) ); - auto bin_key = fc::raw::unpack(bin); - fc::ecc::public_key_data key_data = bin_key.data; - FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check ); - return true; - } - - public_key_type::operator fc::ecc::public_key_data() const - { - return key_data; - }; - - public_key_type::operator fc::ecc::public_key() const - { - return fc::ecc::public_key( key_data ); - }; - - public_key_type::operator std::string() const - { - binary_key k; - k.data = key_data; - k.check = fc::ripemd160::hash( k.data.data, k.data.size() )._hash[0]; - auto data = fc::raw::pack( k ); - return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() ); - } - - bool operator == ( const public_key_type& p1, const fc::ecc::public_key& p2) - { - return p1.key_data == p2.serialize(); - } - - bool operator == ( const public_key_type& p1, const public_key_type& p2) - { - return p1.key_data == p2.key_data; - } - - bool operator != ( const public_key_type& p1, const public_key_type& p2) - { - return p1.key_data != p2.key_data; - } - - // extended_public_key_type - - extended_public_key_type::extended_public_key_type():key_data(){}; - - extended_public_key_type::extended_public_key_type( const fc::ecc::extended_key_data& data ) - :key_data( data ){}; - - extended_public_key_type::extended_public_key_type( const fc::ecc::extended_public_key& extpubkey ) - { - key_data = extpubkey.serialize_extended(); - }; - - extended_public_key_type::extended_public_key_type( const std::string& base58str ) - { - std::string prefix( GRAPHENE_ADDRESS_PREFIX ); - - const size_t prefix_len = prefix.size(); - FC_ASSERT( base58str.size() > prefix_len ); - FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); - auto bin = fc::from_base58( base58str.substr( prefix_len ) ); - auto bin_key = fc::raw::unpack(bin); - FC_ASSERT( fc::ripemd160::hash( bin_key.data.data, bin_key.data.size() )._hash[0] == bin_key.check ); - key_data = bin_key.data; - } - - extended_public_key_type::operator fc::ecc::extended_public_key() const - { - return fc::ecc::extended_public_key::deserialize( key_data ); - } - - extended_public_key_type::operator std::string() const - { - binary_key k; - k.data = key_data; - k.check = fc::ripemd160::hash( k.data.data, k.data.size() )._hash[0]; - auto data = fc::raw::pack( k ); - return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() ); - } - - bool operator == ( const extended_public_key_type& p1, const fc::ecc::extended_public_key& p2) - { - return p1.key_data == p2.serialize_extended(); - } - - bool operator == ( const extended_public_key_type& p1, const extended_public_key_type& p2) - { - return p1.key_data == p2.key_data; - } - - bool operator != ( const extended_public_key_type& p1, const extended_public_key_type& p2) - { - return p1.key_data != p2.key_data; - } - - // extended_private_key_type - - extended_private_key_type::extended_private_key_type():key_data(){}; - - extended_private_key_type::extended_private_key_type( const fc::ecc::extended_key_data& data ) - :key_data( data ){}; - - extended_private_key_type::extended_private_key_type( const fc::ecc::extended_private_key& extprivkey ) - { - key_data = extprivkey.serialize_extended(); - }; - - extended_private_key_type::extended_private_key_type( const std::string& base58str ) - { - std::string prefix( GRAPHENE_ADDRESS_PREFIX ); - - const size_t prefix_len = prefix.size(); - FC_ASSERT( base58str.size() > prefix_len ); - FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); - auto bin = fc::from_base58( base58str.substr( prefix_len ) ); - auto bin_key = fc::raw::unpack(bin); - FC_ASSERT( fc::ripemd160::hash( bin_key.data.data, bin_key.data.size() )._hash[0] == bin_key.check ); - key_data = bin_key.data; - } - - extended_private_key_type::operator fc::ecc::extended_private_key() const - { - return fc::ecc::extended_private_key::deserialize( key_data ); - } - - extended_private_key_type::operator std::string() const - { - binary_key k; - k.data = key_data; - k.check = fc::ripemd160::hash( k.data.data, k.data.size() )._hash[0]; - auto data = fc::raw::pack( k ); - return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() ); - } - - bool operator == ( const extended_private_key_type& p1, const fc::ecc::extended_public_key& p2) - { - return p1.key_data == p2.serialize_extended(); - } - - bool operator == ( const extended_private_key_type& p1, const extended_private_key_type& p2) - { - return p1.key_data == p2.key_data; - } - - bool operator != ( const extended_private_key_type& p1, const extended_private_key_type& p2) - { - return p1.key_data != p2.key_data; - } - -} } // graphene::chain - -namespace fc -{ - using namespace std; - void to_variant( const graphene::chain::public_key_type& var, fc::variant& vo, uint32_t max_depth ) - { - vo = std::string( var ); - } - - void from_variant( const fc::variant& var, graphene::chain::public_key_type& vo, uint32_t max_depth ) - { - vo = graphene::chain::public_key_type( var.as_string() ); - } - - void to_variant( const graphene::chain::extended_public_key_type& var, fc::variant& vo, uint32_t max_depth ) - { - vo = std::string( var ); - } - - void from_variant( const fc::variant& var, graphene::chain::extended_public_key_type& vo, uint32_t max_depth ) - { - vo = graphene::chain::extended_public_key_type( var.as_string() ); - } - - void to_variant( const graphene::chain::extended_private_key_type& var, fc::variant& vo, uint32_t max_depth ) - { - vo = std::string( var ); - } - - void from_variant( const fc::variant& var, graphene::chain::extended_private_key_type& vo, uint32_t max_depth ) - { - vo = graphene::chain::extended_private_key_type( var.as_string() ); - } -} // fc diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 24166e4e..7ec4ad19 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -#include +#include #include #include @@ -37,15 +37,20 @@ #include #include #include -#include +#include #include #include #include #include #include +#include #include +namespace graphene { namespace chain { +FC_IMPLEMENT_EXCEPTION(no_transition, 100000, "Invalid state transition"); +} } + GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::balance_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::block_summary_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::budget_record ) @@ -66,7 +71,7 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_transa GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::son_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::son_statistics_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::special_authority_object ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::transaction_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::transaction_history_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_scheduler ) diff --git a/libraries/chain/son_evaluator.cpp b/libraries/chain/son_evaluator.cpp index 776eb065..191d8f2e 100644 --- a/libraries/chain/son_evaluator.cpp +++ b/libraries/chain/son_evaluator.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -40,7 +41,7 @@ object_id_type create_son_evaluator::do_apply(const son_create_operation& op) { try { vote_id_type vote_id; db().modify(db().get_global_properties(), [&vote_id](global_property_object& p) { - vote_id = get_next_vote_id(p, vote_id_type::son); + vote_id = vote_id_type(vote_id_type::son, p.next_available_vote_id++); }); const auto& new_son_object = db().create( [&]( son_object& obj ){ diff --git a/libraries/chain/special_authority.cpp b/libraries/chain/special_authority.cpp index 74889f80..78372cce 100644 --- a/libraries/chain/special_authority.cpp +++ b/libraries/chain/special_authority.cpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -#include +#include #include #include diff --git a/libraries/chain/tournament_evaluator.cpp b/libraries/chain/tournament_evaluator.cpp index c90f5e10..d3c7acf7 100644 --- a/libraries/chain/tournament_evaluator.cpp +++ b/libraries/chain/tournament_evaluator.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -106,8 +106,7 @@ namespace graphene { namespace chain { object_id_type tournament_create_evaluator::do_apply( const tournament_create_operation& op ) { try { const tournament_details_object& tournament_details = - db().create( [&]( tournament_details_object& a ) { - }); + db().create( [&]( tournament_details_object& ) { }); const tournament_object& new_tournament = db().create( [&]( tournament_object& t ) { diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp index 056652e5..382f98c2 100644 --- a/libraries/chain/tournament_object.cpp +++ b/libraries/chain/tournament_object.cpp @@ -317,7 +317,7 @@ namespace graphene { namespace chain { share_type rake_amount = 0; if (dividend_id) - rake_amount = (fc::uint128_t(tournament_obj.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); + rake_amount = (fc::uint128_t(tournament_obj.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100); asset won_prize(tournament_obj.prize_pool - rake_amount, tournament_obj.options.buy_in.asset_id); tournament_payout_operation op; @@ -646,13 +646,6 @@ namespace graphene { namespace chain { } } - fc::sha256 rock_paper_scissors_throw::calculate_hash() const - { - std::vector full_throw_packed(fc::raw::pack(*this)); - return fc::sha256::hash(full_throw_packed.data(), full_throw_packed.size()); - } - - vector tournament_players_index::get_registered_tournaments_for_account( const account_id_type& a )const { auto iter = account_to_joined_tournaments.find(a); @@ -661,7 +654,12 @@ namespace graphene { namespace chain { return vector(); } - void tournament_players_index::object_inserted(const object& obj) + void tournament_players_index::object_loaded(const object& obj) + { + object_created(obj); + } + + void tournament_players_index::object_created(const object& obj) { assert( dynamic_cast(&obj) ); // for debug only const tournament_details_object& details = static_cast(obj); diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 56eef193..4b9c0e23 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index 3334d4f6..4dea7789 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -59,7 +59,7 @@ asset linear_vesting_policy::get_allowed_withdraw( const vesting_policy_context& share_type total_vested = 0; if( elapsed_seconds < vesting_duration_seconds ) { - total_vested = (fc::uint128_t( begin_balance.value ) * elapsed_seconds / vesting_duration_seconds).to_uint64(); + total_vested = (fc::uint128_t( begin_balance.value ) * elapsed_seconds / vesting_duration_seconds); } else { @@ -127,7 +127,7 @@ asset cdd_vesting_policy::get_allowed_withdraw(const vesting_policy_context& ctx fc::uint128_t cs_earned = compute_coin_seconds_earned(ctx); fc::uint128_t withdraw_available = cs_earned / std::max(vesting_seconds, 1u); assert(withdraw_available <= ctx.balance.amount.value); - return asset(withdraw_available.to_uint64(), ctx.balance.asset_id); + return asset(static_cast(withdraw_available), ctx.balance.asset_id); } void cdd_vesting_policy::on_deposit(const vesting_policy_context& ctx) diff --git a/libraries/chain/witness_evaluator.cpp b/libraries/chain/witness_evaluator.cpp index 7bd261bb..dd45e743 100644 --- a/libraries/chain/witness_evaluator.cpp +++ b/libraries/chain/witness_evaluator.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include namespace graphene { namespace chain { @@ -40,7 +40,7 @@ object_id_type witness_create_evaluator::do_apply( const witness_create_operatio { try { vote_id_type vote_id; db().modify(db().get_global_properties(), [&vote_id](global_property_object& p) { - vote_id = get_next_vote_id(p, vote_id_type::witness); + vote_id = vote_id_type(vote_id_type::witness, p.next_available_vote_id++); }); const auto& new_witness_object = db().create( [&]( witness_object& obj ) { diff --git a/libraries/chain/worker_evaluator.cpp b/libraries/chain/worker_evaluator.cpp index b5aea8f3..b57396cf 100644 --- a/libraries/chain/worker_evaluator.cpp +++ b/libraries/chain/worker_evaluator.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include namespace graphene { namespace chain { @@ -84,8 +84,8 @@ object_id_type worker_create_evaluator::do_apply(const worker_create_evaluator:: database& d = db(); vote_id_type for_id, against_id; d.modify(d.get_global_properties(), [&for_id, &against_id](global_property_object& p) { - for_id = get_next_vote_id(p, vote_id_type::worker); - against_id = get_next_vote_id(p, vote_id_type::worker); + for_id = vote_id_type(vote_id_type::worker, p.next_available_vote_id++); + against_id = vote_id_type(vote_id_type::worker, p.next_available_vote_id++); }); return d.create([&](worker_object& w) { diff --git a/libraries/db/CMakeLists.txt b/libraries/db/CMakeLists.txt index 6feb985c..8ec6fea1 100644 --- a/libraries/db/CMakeLists.txt +++ b/libraries/db/CMakeLists.txt @@ -1,6 +1,19 @@ file(GLOB HEADERS "include/graphene/db/*.hpp") -add_library( graphene_db undo_database.cpp index.cpp object_database.cpp ${HEADERS} ) -target_link_libraries( graphene_db fc ) + +set( GRAPHENE_DB_FILES + undo_database.cpp + index.cpp + object_database.cpp + ${HEADERS} + ) + +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_db ${GRAPHENE_DB_FILES} ) +else() + add_library( graphene_db SHARED ${GRAPHENE_DB_FILES} ) +endif() + +target_link_libraries( graphene_db graphene_protocol fc ) target_include_directories( graphene_db PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) install( TARGETS diff --git a/libraries/db/include/graphene/db/flat_index.hpp b/libraries/db/include/graphene/db/flat_index.hpp index f1b7912e..0d17cbfa 100644 --- a/libraries/db/include/graphene/db/flat_index.hpp +++ b/libraries/db/include/graphene/db/flat_index.hpp @@ -93,14 +93,6 @@ namespace graphene { namespace db { } FC_CAPTURE_AND_RETHROW() } - virtual fc::uint128 hash()const override { - fc::uint128 result; - for( const auto& ptr : _objects ) - result += ptr.hash(); - - return result; - } - class const_iterator { public: diff --git a/libraries/db/include/graphene/db/fwd.hpp b/libraries/db/include/graphene/db/fwd.hpp index 36b4e713..76c514dd 100644 --- a/libraries/db/include/graphene/db/fwd.hpp +++ b/libraries/db/include/graphene/db/fwd.hpp @@ -33,3 +33,4 @@ namespace graphene { namespace db { typedef std::shared_ptr peer_ram_ptr; }} // namespace graphene::db + diff --git a/libraries/db/include/graphene/db/generic_index.hpp b/libraries/db/include/graphene/db/generic_index.hpp index fb11d44a..812a6587 100644 --- a/libraries/db/include/graphene/db/generic_index.hpp +++ b/libraries/db/include/graphene/db/generic_index.hpp @@ -28,12 +28,12 @@ #include #include -namespace graphene { namespace chain { +namespace graphene { namespace db { using boost::multi_index_container; using namespace boost::multi_index; - struct by_id{}; + struct by_id; /** * Almost all objects can be tracked and managed via a boost::multi_index container that uses * an unordered_unique key on the object ID. This template class adapts the generic index interface @@ -112,18 +112,7 @@ namespace graphene { namespace chain { const index_type& indices()const { return _indices; } - virtual fc::uint128 hash()const override { - fc::uint128 result; - for( const auto& ptr : _indices ) - { - result += ptr.hash(); - } - - return result; - } - private: - fc::uint128 _current_hash; index_type _indices; }; diff --git a/libraries/db/include/graphene/db/index.hpp b/libraries/db/include/graphene/db/index.hpp index 1bc593f4..2aa7cb9a 100644 --- a/libraries/db/include/graphene/db/index.hpp +++ b/libraries/db/include/graphene/db/index.hpp @@ -129,20 +129,29 @@ namespace graphene { namespace db { } virtual void inspect_all_objects(std::function inspector)const = 0; - virtual fc::uint128 hash()const = 0; virtual void add_observer( const shared_ptr& ) = 0; virtual void object_from_variant( const fc::variant& var, object& obj, uint32_t max_depth )const = 0; virtual void object_default( object& obj )const = 0; }; + /** @class secondary_index + * @brief A secondary index is intended to observe a primary index. + * A secondary index is not automatically persisted when the node shuts own. + */ class secondary_index { public: virtual ~secondary_index(){}; - virtual void object_inserted( const object& obj ){}; + // Called when an object from a previous node session is loaded from persistence + virtual void object_loaded( const object& obj ){}; + // Called when an object from the current node session is created + virtual void object_created( const object& obj ){}; + // Called when an object is removed virtual void object_removed( const object& obj ){}; + // Called when an object is about to be modified virtual void about_to_modify( const object& before ){}; + // Called when an object is modified virtual void object_modified( const object& after ){}; }; @@ -184,6 +193,13 @@ namespace graphene { namespace db { FC_THROW_EXCEPTION( fc::assert_exception, "invalid index type" ); } + void delete_secondary_index(const secondary_index& secondary) { + auto itr = std::find_if(_sindex.begin(), _sindex.end(), + [&secondary](const auto& ptr) { return &secondary == ptr.get(); }); + FC_ASSERT(itr != _sindex.end(), "Cannot remove secondary index: secondary index not found"); + _sindex.erase(itr); + } + protected: vector< shared_ptr > _observers; vector< unique_ptr > _sindex; @@ -220,7 +236,12 @@ namespace graphene { namespace db { virtual ~direct_index(){} - virtual void object_inserted( const object& obj ) + virtual void object_loaded( const object& obj ) + { + object_created(obj); + } + + virtual void object_created( const object& obj ) { uint64_t instance = obj.id.instance(); if( instance == next ) @@ -380,7 +401,7 @@ namespace graphene { namespace db { { const auto& result = DerivedIndex::insert( fc::raw::unpack( data ) ); for( const auto& item : _sindex ) - item->object_inserted( result ); + item->object_loaded( result ); return result; } @@ -389,7 +410,7 @@ namespace graphene { namespace db { { const auto& result = DerivedIndex::create( constructor ); for( const auto& item : _sindex ) - item->object_inserted( result ); + item->object_created( result ); on_add( result ); return result; } diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index c410e273..2c0f2adc 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include -#include +#include #define MAX_NESTING (200) @@ -77,7 +77,6 @@ namespace graphene { namespace db { virtual void move_from( object& obj ) = 0; virtual variant to_variant()const = 0; virtual vector pack()const = 0; - virtual fc::uint128 hash()const = 0; }; /** @@ -102,10 +101,6 @@ namespace graphene { namespace db { } virtual variant to_variant()const { return variant( static_cast(*this), MAX_NESTING ); } virtual vector pack()const { return fc::raw::pack( static_cast(*this) ); } - virtual fc::uint128 hash()const { - auto tmp = this->pack(); - return fc::city_hash_crc_128( tmp.data(), tmp.size() ); - } }; typedef flat_map annotation_map; @@ -139,6 +134,13 @@ namespace graphene { namespace db { } } // graphene::db +// Without this, pack(object_id) tries to match the template for +// pack(boost::multiprecision::uint128_t). No idea why. :-( +namespace boost { namespace multiprecision { namespace detail { +template +struct is_restricted_conversion : public mpl::true_ {}; +}}} + FC_REFLECT_TYPENAME( graphene::db::annotation_map ) FC_REFLECT( graphene::db::object, (id) ) FC_REFLECT_DERIVED_TEMPLATE( (typename Derived), graphene::db::annotated_object, (graphene::db::object), (annotations) ) diff --git a/libraries/db/include/graphene/db/object_database.hpp b/libraries/db/include/graphene/db/object_database.hpp index fa2109aa..ede9600c 100644 --- a/libraries/db/include/graphene/db/object_database.hpp +++ b/libraries/db/include/graphene/db/object_database.hpp @@ -75,6 +75,10 @@ namespace graphene { namespace db { const index& get_index()const { return get_index(T::space_id,T::type_id); } const index& get_index(uint8_t space_id, uint8_t type_id)const; const index& get_index(object_id_type id)const { return get_index(id.space(),id.type()); } + template + const index* find_index()const { return find_index(T::space_id,T::type_id); } + const index* find_index(object_id_type id)const { return find_index(id.space(), id.type()); } + const index* find_index(uint8_t space_id, uint8_t type_id)const; /// @} const object& get_object( object_id_type id )const; @@ -121,11 +125,15 @@ namespace graphene { namespace db { return static_cast(obj); } - template - const T* find( object_id id )const { return find(id); } + template + auto find( object_id id )const -> const object_downcast_t* { + return find>(id); + } - template - const T& get( object_id id )const { return get(id); } + template + auto get( object_id id )const -> const object_downcast_t& { + return get>(id); + } template IndexType* add_index() @@ -139,6 +147,43 @@ namespace graphene { namespace db { return static_cast(_index[ObjectType::space_id][ObjectType::type_id].get()); } + template + SecondaryIndexType* add_secondary_index() + { + return get_mutable_index_type().template add_secondary_index(); + } + template + SecondaryIndexType* add_secondary_index(const uint8_t space_id, const uint8_t type_id) + { + auto* base_primary = dynamic_cast(&get_mutable_index(space_id, type_id)); + FC_ASSERT(base_primary != nullptr, + "Cannot add secondary index: index for space ID ${S} and type ID ${T} does not support secondary indexes.", + ("S", space_id)("T", type_id)); + return base_primary->template add_secondary_index(); + } + + template + void delete_secondary_index(const secondary_index& secondary) { + get_mutable_index_type().delete_secondary_index(secondary); + } + void delete_secondary_index(const uint8_t space_id, const uint8_t type_id, const secondary_index& secondary) { + auto* base_primary = dynamic_cast(&get_mutable_index(space_id, type_id)); + FC_ASSERT(base_primary != nullptr, + "Cannot add secondary index: index for space ID ${S} and type ID ${T} does not support secondary indexes.", + ("S", space_id)("T", type_id)); + base_primary->delete_secondary_index(secondary); + } + + // Inspect each index in an object space. F is a callable taking a const index& + template + void inspect_all_indexes(uint8_t space_id, F&& f) const { + FC_ASSERT(_index.size() > space_id, "Cannot inspect indexes in space ID ${ID}: no such object space", + ("ID", space_id)); + for (const auto& ptr : _index[space_id]) + if (ptr != nullptr) + f((const index&)(*ptr)); + } + void pop_undo(); fc::path get_data_dir()const { return _data_dir; } diff --git a/libraries/db/include/graphene/db/simple_index.hpp b/libraries/db/include/graphene/db/simple_index.hpp index 0e807aef..51679be2 100644 --- a/libraries/db/include/graphene/db/simple_index.hpp +++ b/libraries/db/include/graphene/db/simple_index.hpp @@ -98,13 +98,6 @@ namespace graphene { namespace db { } } FC_CAPTURE_AND_RETHROW() } - virtual fc::uint128 hash()const override { - fc::uint128 result; - for( const auto& ptr : _objects ) - result += ptr->hash(); - - return result; - } class const_iterator { diff --git a/libraries/db/object_database.cpp b/libraries/db/object_database.cpp index fdde0fed..2f8d9565 100644 --- a/libraries/db/object_database.cpp +++ b/libraries/db/object_database.cpp @@ -25,7 +25,6 @@ #include #include -#include namespace graphene { namespace db { @@ -59,6 +58,13 @@ const index& object_database::get_index(uint8_t space_id, uint8_t type_id)const FC_ASSERT( tmp ); return *tmp; } + +const index* object_database::find_index(uint8_t space_id, uint8_t type_id) const +{ + if (_index.size() > space_id && _index[space_id].size() > type_id) + return _index[space_id][type_id].get(); + return nullptr; +} index& object_database::get_mutable_index(uint8_t space_id, uint8_t type_id) { FC_ASSERT( _index.size() > space_id, "", ("space_id",space_id)("type_id",type_id)("index.size",_index.size()) ); diff --git a/libraries/egenesis/CMakeLists.txt b/libraries/egenesis/CMakeLists.txt index 75589999..ee6dc4a1 100644 --- a/libraries/egenesis/CMakeLists.txt +++ b/libraries/egenesis/CMakeLists.txt @@ -57,3 +57,5 @@ INSTALL( TARGETS LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) +file(GLOB HEADERS "include/graphene/egenesis/*.hpp") +INSTALL( FILES ${HEADERS} DESTINATION "include/graphene/egenesis" ) diff --git a/libraries/egenesis/egenesis_brief.cpp.tmpl b/libraries/egenesis/egenesis_brief.cpp.tmpl index bd590eb3..bb4a7e58 100644 --- a/libraries/egenesis/egenesis_brief.cpp.tmpl +++ b/libraries/egenesis/egenesis_brief.cpp.tmpl @@ -17,7 +17,7 @@ ${generated_file_banner} * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include namespace graphene { namespace egenesis { diff --git a/libraries/egenesis/egenesis_full.cpp.tmpl b/libraries/egenesis/egenesis_full.cpp.tmpl index 83285f11..2b172fa0 100644 --- a/libraries/egenesis/egenesis_full.cpp.tmpl +++ b/libraries/egenesis/egenesis_full.cpp.tmpl @@ -17,7 +17,7 @@ ${generated_file_banner} * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include namespace graphene { namespace egenesis { diff --git a/libraries/egenesis/embed_genesis.cpp b/libraries/egenesis/embed_genesis.cpp index c2ffd686..b4c7d91c 100644 --- a/libraries/egenesis/embed_genesis.cpp +++ b/libraries/egenesis/embed_genesis.cpp @@ -34,10 +34,10 @@ #include #include #include -#include +#include // we need to include the world in order to serialize fee_parameters -#include +#include using namespace graphene::chain; diff --git a/libraries/egenesis/include/graphene/egenesis/egenesis.hpp b/libraries/egenesis/include/graphene/egenesis/egenesis.hpp index 848a4d29..8d575301 100644 --- a/libraries/egenesis/include/graphene/egenesis/egenesis.hpp +++ b/libraries/egenesis/include/graphene/egenesis/egenesis.hpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include namespace graphene { namespace egenesis { diff --git a/libraries/fc b/libraries/fc index 48888392..a17b231a 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 488883921936139e8734b99822d3a589afe80da1 +Subproject commit a17b231acf3bbd448179ddffc63c655e9b326395 diff --git a/libraries/net/CMakeLists.txt b/libraries/net/CMakeLists.txt index 1cc71728..2dcc2c78 100644 --- a/libraries/net/CMakeLists.txt +++ b/libraries/net/CMakeLists.txt @@ -3,15 +3,24 @@ file(GLOB HEADERS "include/graphene/net/*.hpp") set(SOURCES node.cpp stcp_socket.cpp core_messages.cpp + exceptions.cpp peer_database.cpp peer_connection.cpp message.cpp message_oriented_connection.cpp) -add_library( graphene_net ${SOURCES} ${HEADERS} ) +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_net ${SOURCES} ${HEADERS} ) +else() + add_library( graphene_net SHARED ${SOURCES} ${HEADERS} ) +endif() -target_link_libraries( graphene_net graphene_chain ) -target_include_directories( graphene_net PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) +target_link_libraries( graphene_net + PUBLIC fc graphene_db graphene_protocol ) +target_include_directories( graphene_net + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../chain/include" "${CMAKE_CURRENT_BINARY_DIR}/../chain/include" +) if(MSVC) set_source_files_properties( node.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) diff --git a/libraries/chain/protocol/small_ops.cpp b/libraries/net/exceptions.cpp similarity index 51% rename from libraries/chain/protocol/small_ops.cpp rename to libraries/net/exceptions.cpp index cba4b1b7..7b6e23dc 100644 --- a/libraries/chain/protocol/small_ops.cpp +++ b/libraries/net/exceptions.cpp @@ -21,23 +21,21 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include -#include -#include -#include -#include -#include -#include +namespace graphene { namespace net { -#include + FC_IMPLEMENT_EXCEPTION( net_exception, 90000, "P2P Networking Exception" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( send_queue_overflow, net_exception, 90001, + "send queue for this peer exceeded maximum size" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( insufficient_relay_fee, net_exception, 90002, + "insufficient relay fee" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( already_connected_to_requested_peer, net_exception, 90003, + "already connected to requested peer" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( block_older_than_undo_history, net_exception, 90004, + "block is older than our undo history allows us to process" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( peer_is_on_an_unreachable_fork, net_exception, 90005, + "peer is on another fork" ) + FC_IMPLEMENT_DERIVED_EXCEPTION( unlinkable_block_exception, net_exception, 90006, "unlinkable block" ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::balance_claim_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::buyback_account_options ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::fba_distribute_operation ) - -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::vesting_balance_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::vesting_balance_withdraw_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::vesting_balance_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::vesting_balance_withdraw_operation ) - -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::chain_parameters ) +} } diff --git a/libraries/net/include/graphene/net/core_messages.hpp b/libraries/net/include/graphene/net/core_messages.hpp index 8af0c344..39d68fba 100644 --- a/libraries/net/include/graphene/net/core_messages.hpp +++ b/libraries/net/include/graphene/net/core_messages.hpp @@ -24,7 +24,7 @@ #pragma once #include -#include +#include #include #include @@ -40,10 +40,10 @@ #include namespace graphene { namespace net { - using graphene::chain::signed_transaction; - using graphene::chain::block_id_type; - using graphene::chain::transaction_id_type; - using graphene::chain::signed_block; + using graphene::protocol::signed_transaction; + using graphene::protocol::block_id_type; + using graphene::protocol::transaction_id_type; + using graphene::protocol::signed_block; typedef fc::ecc::public_key_data node_id_t; typedef fc::ripemd160 item_hash_t; diff --git a/libraries/net/include/graphene/net/exceptions.hpp b/libraries/net/include/graphene/net/exceptions.hpp index 59da8ccb..e95eea87 100644 --- a/libraries/net/include/graphene/net/exceptions.hpp +++ b/libraries/net/include/graphene/net/exceptions.hpp @@ -27,12 +27,12 @@ namespace graphene { namespace net { // registered in node.cpp - FC_DECLARE_EXCEPTION( net_exception, 90000, "P2P Networking Exception" ); - FC_DECLARE_DERIVED_EXCEPTION( send_queue_overflow, graphene::net::net_exception, 90001, "send queue for this peer exceeded maximum size" ); - FC_DECLARE_DERIVED_EXCEPTION( insufficient_relay_fee, graphene::net::net_exception, 90002, "insufficient relay fee" ); - FC_DECLARE_DERIVED_EXCEPTION( already_connected_to_requested_peer, graphene::net::net_exception, 90003, "already connected to requested peer" ); - FC_DECLARE_DERIVED_EXCEPTION( block_older_than_undo_history, graphene::net::net_exception, 90004, "block is older than our undo history allows us to process" ); - FC_DECLARE_DERIVED_EXCEPTION( peer_is_on_an_unreachable_fork, graphene::net::net_exception, 90005, "peer is on another fork" ); - FC_DECLARE_DERIVED_EXCEPTION( unlinkable_block_exception, graphene::net::net_exception, 90006, "unlinkable block" ) + FC_DECLARE_EXCEPTION( net_exception, 90000 ) + FC_DECLARE_DERIVED_EXCEPTION( send_queue_overflow, net_exception, 90001 ) + FC_DECLARE_DERIVED_EXCEPTION( insufficient_relay_fee, net_exception, 90002 ) + FC_DECLARE_DERIVED_EXCEPTION( already_connected_to_requested_peer, net_exception, 90003 ) + FC_DECLARE_DERIVED_EXCEPTION( block_older_than_undo_history, net_exception, 90004 ) + FC_DECLARE_DERIVED_EXCEPTION( peer_is_on_an_unreachable_fork, net_exception, 90005 ) + FC_DECLARE_DERIVED_EXCEPTION( unlinkable_block_exception, net_exception, 90006 ) } } diff --git a/libraries/net/include/graphene/net/message.hpp b/libraries/net/include/graphene/net/message.hpp index 686fea24..1807eb16 100644 --- a/libraries/net/include/graphene/net/message.hpp +++ b/libraries/net/include/graphene/net/message.hpp @@ -24,9 +24,8 @@ #pragma once #include -#include +#include -#include #include #include #include diff --git a/libraries/net/include/graphene/net/node.hpp b/libraries/net/include/graphene/net/node.hpp index e17af148..fe03ac0c 100644 --- a/libraries/net/include/graphene/net/node.hpp +++ b/libraries/net/include/graphene/net/node.hpp @@ -27,14 +27,14 @@ #include #include -#include +#include #include namespace graphene { namespace net { using fc::variant_object; - using graphene::chain::chain_id_type; + using graphene::protocol::chain_id_type; namespace detail { @@ -193,7 +193,7 @@ namespace graphene { namespace net { { public: node(const std::string& user_agent); - ~node(); + virtual ~node(); void close(); @@ -272,8 +272,8 @@ namespace graphene { namespace net { void set_advanced_node_parameters(const fc::variant_object& params); fc::variant_object get_advanced_node_parameters(); - message_propagation_data get_transaction_propagation_data(const graphene::chain::transaction_id_type& transaction_id); - message_propagation_data get_block_propagation_data(const graphene::chain::block_id_type& block_id); + message_propagation_data get_transaction_propagation_data(const graphene::protocol::transaction_id_type& transaction_id); + message_propagation_data get_block_propagation_data(const graphene::protocol::block_id_type& block_id); node_id_t get_node_id() const; void set_allowed_peers(const std::vector& allowed_peers); diff --git a/libraries/net/include/graphene/net/peer_database.hpp b/libraries/net/include/graphene/net/peer_database.hpp index ff7f4036..931f6e33 100644 --- a/libraries/net/include/graphene/net/peer_database.hpp +++ b/libraries/net/include/graphene/net/peer_database.hpp @@ -24,7 +24,7 @@ #pragma once #include -#include +#include #include #include diff --git a/libraries/net/include/graphene/net/stcp_socket.hpp b/libraries/net/include/graphene/net/stcp_socket.hpp index cca94d57..fb4bfbc7 100644 --- a/libraries/net/include/graphene/net/stcp_socket.hpp +++ b/libraries/net/include/graphene/net/stcp_socket.hpp @@ -26,6 +26,8 @@ #include #include +#include + namespace graphene { namespace net { /** @@ -61,8 +63,6 @@ class stcp_socket : public virtual fc::iostream fc::sha512 _shared_secret; fc::ecc::private_key _priv_key; - fc::array _buf; - //uint32_t _buf_len; fc::tcp_socket _sock; fc::aes_encoder _send_aes; fc::aes_decoder _recv_aes; diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 3222da08..6222d6f9 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -79,7 +79,10 @@ #include #include -#include +// Nasty hack: A circular dependency around fee_schedule is resolved by fwd-declaring it and using a shared_ptr +// to it in chain_parameters, which is used in an operation and thus must be serialized by the net library. +// Resolving that forward declaration doesn't happen until now: +#include #include @@ -827,7 +830,7 @@ namespace graphene { namespace net { namespace detail { _maximum_blocks_per_peer_during_syncing(GRAPHENE_NET_MAX_BLOCKS_PER_PEER_DURING_SYNCING) { _rate_limiter.set_actual_rate_time_constant(fc::seconds(2)); - fc::rand_bytes(&_node_id.data[0], (int)_node_id.size()); + fc::rand_bytes((char*) _node_id.data(), (int)_node_id.size()); } node_impl::~node_impl() @@ -948,7 +951,7 @@ namespace graphene { namespace net { namespace detail { #if 0 try { - _retrigger_connect_loop_promise = fc::promise::ptr( new fc::promise("graphene::net::retrigger_connect_loop") ); + _retrigger_connect_loop_promise = fc::promise::create("graphene::net::retrigger_connect_loop"); if( is_wanting_new_connections() || !_add_once_node_list.empty() ) { if( is_wanting_new_connections() ) @@ -1078,7 +1081,7 @@ namespace graphene { namespace net { namespace detail { if( !_sync_items_to_fetch_updated ) { dlog( "no sync items to fetch right now, going to sleep" ); - _retrigger_fetch_sync_items_loop_promise = fc::promise::ptr( new fc::promise("graphene::net::retrigger_fetch_sync_items_loop") ); + _retrigger_fetch_sync_items_loop_promise = fc::promise::create("graphene::net::retrigger_fetch_sync_items_loop"); _retrigger_fetch_sync_items_loop_promise->wait(); _retrigger_fetch_sync_items_loop_promise.reset(); } @@ -1205,7 +1208,7 @@ namespace graphene { namespace net { namespace detail { if (!_items_to_fetch_updated) { - _retrigger_fetch_item_loop_promise = fc::promise::ptr(new fc::promise("graphene::net::retrigger_fetch_item_loop")); + _retrigger_fetch_item_loop_promise = fc::promise::create("graphene::net::retrigger_fetch_item_loop"); fc::microseconds time_until_retrigger = fc::microseconds::maximum(); if (next_peer_unblocked_time != fc::time_point::maximum()) time_until_retrigger = next_peer_unblocked_time - fc::time_point::now(); @@ -1297,7 +1300,7 @@ namespace graphene { namespace net { namespace detail { if (_new_inventory.empty()) { - _retrigger_advertise_inventory_loop_promise = fc::promise::ptr(new fc::promise("graphene::net::retrigger_advertise_inventory_loop")); + _retrigger_advertise_inventory_loop_promise = fc::promise::create("graphene::net::retrigger_advertise_inventory_loop"); _retrigger_advertise_inventory_loop_promise->wait(); _retrigger_advertise_inventory_loop_promise.reset(); } @@ -1337,7 +1340,7 @@ namespace graphene { namespace net { namespace detail { uint32_t handshaking_timeout = _peer_inactivity_timeout; fc::time_point handshaking_disconnect_threshold = fc::time_point::now() - fc::seconds(handshaking_timeout); - for( const peer_connection_ptr handshaking_peer : _handshaking_connections ) + for( const peer_connection_ptr& handshaking_peer : _handshaking_connections ) if( handshaking_peer->connection_initiation_time < handshaking_disconnect_threshold && handshaking_peer->get_last_message_received_time() < handshaking_disconnect_threshold && handshaking_peer->get_last_message_sent_time() < handshaking_disconnect_threshold ) @@ -1702,13 +1705,13 @@ namespace graphene { namespace net { namespace detail { dlog("is_already_connected_to_id returning true because the peer is us"); return true; } - for (const peer_connection_ptr active_peer : _active_connections) + for (const peer_connection_ptr& active_peer : _active_connections) if (node_id == active_peer->node_id) { dlog("is_already_connected_to_id returning true because the peer is already in our active list"); return true; } - for (const peer_connection_ptr handshaking_peer : _handshaking_connections) + for (const peer_connection_ptr& handshaking_peer : _handshaking_connections) if (node_id == handshaking_peer->node_id) { dlog("is_already_connected_to_id returning true because the peer is already in our handshaking list"); @@ -2876,7 +2879,7 @@ namespace graphene { namespace net { namespace detail { item_id advertised_item_id(item_ids_inventory_message_received.item_type, item_hash); bool we_advertised_this_item_to_a_peer = false; bool we_requested_this_item_from_a_peer = false; - for (const peer_connection_ptr peer : _active_connections) + for (const peer_connection_ptr& peer : _active_connections) { if (peer->inventory_advertised_to_peer.find(advertised_item_id) != peer->inventory_advertised_to_peer.end()) { diff --git a/libraries/net/peer_connection.cpp b/libraries/net/peer_connection.cpp index 9b753e6c..44a803d1 100644 --- a/libraries/net/peer_connection.cpp +++ b/libraries/net/peer_connection.cpp @@ -24,8 +24,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp index 784c7e45..9f042a13 100644 --- a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp +++ b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp @@ -84,7 +84,8 @@ class account_history_plugin : public graphene::app::plugin class affiliate_reward_index : public secondary_index { public: - virtual void object_inserted( const object& obj ) override; + virtual void object_loaded( const object& obj ) override; + virtual void object_created( const object& obj ) override; virtual void object_removed( const object& obj ) override; virtual void about_to_modify( const object& before ) override{}; virtual void object_modified( const object& after ) override{}; @@ -93,28 +94,3 @@ class affiliate_reward_index : public secondary_index }; } } //graphene::account_history - -/*struct by_id; -struct by_seq; -struct by_op; -typedef boost::multi_index_container< - graphene::chain::account_transaction_history_object, - boost::multi_index::indexed_by< - boost::multi_index::ordered_unique< tag, member< object, object_id_type, &object::id > >, - boost::multi_index::ordered_unique< tag, - composite_key< account_transaction_history_object, - member< account_transaction_history_object, account_id_type, &account_transaction_history_object::account>, - member< account_transaction_history_object, uint32_t, &account_transaction_history_object::sequence> - > - >, - boost::multi_index::ordered_unique< tag, - composite_key< account_transaction_history_object, - member< account_transaction_history_object, account_id_type, &account_transaction_history_object::account>, - member< account_transaction_history_object, operation_history_id_type, &account_transaction_history_object::operation_id> - > - > - > -> account_transaction_history_multi_index_type; - -typedef graphene::account_history::generic_index account_transaction_history_index; -*/ diff --git a/libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp b/libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp index 03b54659..7ec59e82 100644 --- a/libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp +++ b/libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp @@ -152,8 +152,8 @@ static optional> get_accou { FC_ASSERT( dynamic_cast(&obj) ); const account_transaction_history_object& ath = static_cast(obj); - const operation_history_object& oho = db.get( ath.operation_id ); - if( oho.op.which() == operation::tag::value ) + const operation_history_object* oho = db.find( ath.operation_id ); + if( oho != nullptr && oho->op.which() == operation::tag::value ) return std::make_pair( ath.account, ath.operation_id ); return optional>(); } diff --git a/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp index 29c45d9f..b9f4ac64 100644 --- a/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp +++ b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp @@ -27,8 +27,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_objects.hpp b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_objects.hpp index 1dc70276..a6d3a63c 100644 --- a/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_objects.hpp +++ b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_objects.hpp @@ -48,7 +48,7 @@ public: inline asset_id_type get_asset_id()const { return total_payout.asset_id; } }; -typedef object_id app_reward_id_type; +typedef object_id app_reward_id_type; struct by_asset; struct by_app_asset; @@ -86,7 +86,7 @@ public: inline asset_id_type get_asset_id()const { return total_payout.asset_id; } }; -typedef object_id referral_reward_id_type; +typedef object_id referral_reward_id_type; struct by_referral_asset; typedef multi_index_container< diff --git a/libraries/plugins/bookie/bookie_api.cpp b/libraries/plugins/bookie/bookie_api.cpp index 9caa9c62..4269364d 100644 --- a/libraries/plugins/bookie/bookie_api.cpp +++ b/libraries/plugins/bookie/bookie_api.cpp @@ -152,7 +152,7 @@ fc::variants bookie_api_impl::get_objects(const vector& ids) con result.reserve(ids.size()); std::transform(ids.begin(), ids.end(), std::back_inserter(result), - [this, &db](object_id_type id) -> fc::variant { + [&db](object_id_type id) -> fc::variant { switch (id.type()) { case event_id_type::type_id: diff --git a/libraries/plugins/bookie/bookie_plugin.cpp b/libraries/plugins/bookie/bookie_plugin.cpp index 5bc31f14..e9f8a9bd 100644 --- a/libraries/plugins/bookie/bookie_plugin.cpp +++ b/libraries/plugins/bookie/bookie_plugin.cpp @@ -54,17 +54,52 @@ namespace detail /* As a plugin, we get notified of new/changed objects at the end of every block processed. * For most objects, that's fine, because we expect them to always be around until the end of * the block. However, with bet objects, it's possible that the user places a bet and it fills - * and is removed during the same block, so need another strategy to detect them immediately after - * they are created. + * and is removed during the same block, so need another strategy to detect these "ephemeral" + * node objects immediately after they are created. * We do this by creating a secondary index on bet_object. We don't actually use it * to index any property of the bet, we just use it to register for callbacks. + * + * One objective of the plugin's helper is to watch for database objects known by the the node + * (node objects) in order for the plugin to populate and persist a copy (plugin objects) + * within its own primary index. + * + * The life cycle of a naive helper object is: + * + * 1. During `plugin_initialize()` + * The helper registers with the database for future notifications (Step 2) of the creation of + * a watched object + * (`database().add_secondary_index<...>()`). + * The helper also delegates the future persistence (Step 3) of its own primary index + * to the database by registering it. + * (`database().add_index>()`). + * This primary index will be used to index plugin objects that are copies of node objects + * observed during Step 2. + * 2. During a node session: the helper is notified by the database about the watched node objects + * that are created during the node session through its `object_created()` callback. + * During that callback, the helper will create its own copy (plugin object) of the of node + * objectand inject it into its own primary index. + * 3. When the node session shuts down, the database will persist the helper's primary index + * that was registered during Step 1. + * 4. When the node is restarted, the database will automatically load the previous session(s)'s + * node objectsinto the helper's primary index. + * + * The helper can ignore the `object_loaded()` events that are triggered when the watched node + * objects are loaded from persistence by the database because those objects were already processed + * by the the helper's `object_created()` during the prior sessions. + * + * NOTE: The helper should register itself for notifications of new node objects + * during `plugin_initialize()` rather than `plugin_startup()` + * for compatibility with a blockchain replay. */ class persistent_bet_object_helper : public secondary_index { public: virtual ~persistent_bet_object_helper() {} - virtual void object_inserted(const object& obj) override; + using watched_index = primary_index; + + //virtual void object_loaded(const object& obj) override; + virtual void object_created(const object& obj) override; //virtual void object_removed( const object& obj ) override; //virtual void about_to_modify( const object& before ) override; virtual void object_modified(const object& after) override; @@ -73,7 +108,7 @@ class persistent_bet_object_helper : public secondary_index bookie_plugin* _bookie_plugin; }; -void persistent_bet_object_helper::object_inserted(const object& obj) +void persistent_bet_object_helper::object_created(const object& obj) { const bet_object& bet_obj = *boost::polymorphic_downcast(&obj); _bookie_plugin->database().create([&](persistent_bet_object& saved_bet_obj) { @@ -99,7 +134,10 @@ class persistent_betting_market_object_helper : public secondary_index public: virtual ~persistent_betting_market_object_helper() {} - virtual void object_inserted(const object& obj) override; + using watched_index = primary_index; + + //virtual void object_loaded(const object& obj) override; + virtual void object_created(const object& obj) override; //virtual void object_removed( const object& obj ) override; //virtual void about_to_modify( const object& before ) override; virtual void object_modified(const object& after) override; @@ -108,7 +146,7 @@ class persistent_betting_market_object_helper : public secondary_index bookie_plugin* _bookie_plugin; }; -void persistent_betting_market_object_helper::object_inserted(const object& obj) +void persistent_betting_market_object_helper::object_created(const object& obj) { const betting_market_object& betting_market_obj = *boost::polymorphic_downcast(&obj); _bookie_plugin->database().create([&](persistent_betting_market_object& saved_betting_market_obj) { @@ -134,7 +172,10 @@ class persistent_betting_market_group_object_helper : public secondary_index public: virtual ~persistent_betting_market_group_object_helper() {} - virtual void object_inserted(const object& obj) override; + using watched_index = primary_index; + + //virtual void object_loaded(const object& obj) override; + virtual void object_created(const object& obj) override; //virtual void object_removed( const object& obj ) override; //virtual void about_to_modify( const object& before ) override; virtual void object_modified(const object& after) override; @@ -143,7 +184,7 @@ class persistent_betting_market_group_object_helper : public secondary_index bookie_plugin* _bookie_plugin; }; -void persistent_betting_market_group_object_helper::object_inserted(const object& obj) +void persistent_betting_market_group_object_helper::object_created(const object& obj) { const betting_market_group_object& betting_market_group_obj = *boost::polymorphic_downcast(&obj); _bookie_plugin->database().create([&](persistent_betting_market_group_object& saved_betting_market_group_obj) { @@ -169,7 +210,10 @@ class persistent_event_object_helper : public secondary_index public: virtual ~persistent_event_object_helper() {} - virtual void object_inserted(const object& obj) override; + using watched_index = primary_index; + + //virtual void object_loaded(const object& obj) override; + virtual void object_created(const object& obj) override; //virtual void object_removed( const object& obj ) override; //virtual void about_to_modify( const object& before ) override; virtual void object_modified(const object& after) override; @@ -178,7 +222,7 @@ class persistent_event_object_helper : public secondary_index bookie_plugin* _bookie_plugin; }; -void persistent_event_object_helper::object_inserted(const object& obj) +void persistent_event_object_helper::object_created(const object& obj) { const event_object& event_obj = *boost::polymorphic_downcast(&obj); _bookie_plugin->database().create([&](persistent_event_object& saved_event_obj) { @@ -465,45 +509,32 @@ void bookie_plugin::plugin_set_program_options(boost::program_options::options_d void bookie_plugin::plugin_initialize(const boost::program_options::variables_map& options) { - ilog("bookie plugin: plugin_startup() begin"); + ilog("bookie plugin: plugin_initialize() begin"); database().force_slow_replays(); database().applied_block.connect( [&]( const signed_block& b){ my->on_block_applied(b); } ); database().changed_objects.connect([&](const vector& changed_object_ids, const fc::flat_set& impacted_accounts){ my->on_objects_changed(changed_object_ids); }); database().new_objects.connect([this](const vector& ids, const flat_set& impacted_accounts) { my->on_objects_new(ids); }); database().removed_objects.connect([this](const vector& ids, const vector& objs, const flat_set& impacted_accounts) { my->on_objects_removed(ids); }); - //auto event_index = database().add_index >(); database().add_index >(); database().add_index >(); database().add_index >(); - const primary_index& bet_object_idx = database().get_index_type >(); - primary_index& nonconst_bet_object_idx = const_cast&>(bet_object_idx); - detail::persistent_bet_object_helper* persistent_bet_object_helper_index = nonconst_bet_object_idx.add_secondary_index(); - persistent_bet_object_helper_index->set_plugin_instance(this); - const primary_index& betting_market_object_idx = database().get_index_type >(); - primary_index& nonconst_betting_market_object_idx = const_cast&>(betting_market_object_idx); - detail::persistent_betting_market_object_helper* persistent_betting_market_object_helper_index = nonconst_betting_market_object_idx.add_secondary_index(); - persistent_betting_market_object_helper_index->set_plugin_instance(this); + // Register secondary indexes + database().add_secondary_index()->set_plugin_instance(this); + database().add_secondary_index()->set_plugin_instance(this); + database().add_secondary_index()->set_plugin_instance(this); + database().add_secondary_index()->set_plugin_instance(this); - const primary_index& betting_market_group_object_idx = database().get_index_type >(); - primary_index& nonconst_betting_market_group_object_idx = const_cast&>(betting_market_group_object_idx); - detail::persistent_betting_market_group_object_helper* persistent_betting_market_group_object_helper_index = nonconst_betting_market_group_object_idx.add_secondary_index(); - persistent_betting_market_group_object_helper_index->set_plugin_instance(this); - - const primary_index& event_object_idx = database().get_index_type >(); - primary_index& nonconst_event_object_idx = const_cast&>(event_object_idx); - detail::persistent_event_object_helper* persistent_event_object_helper_index = nonconst_event_object_idx.add_secondary_index(); - persistent_event_object_helper_index->set_plugin_instance(this); - - ilog("bookie plugin: plugin_startup() end"); + ilog("bookie plugin: plugin_initialize() end"); } void bookie_plugin::plugin_startup() { - ilog("bookie plugin: plugin_startup()"); + ilog("bookie plugin: plugin_startup()"); + my->fill_localized_event_strings(); } @@ -519,7 +550,8 @@ asset bookie_plugin::get_total_matched_bet_amount_for_betting_market_group(betti } std::vector bookie_plugin::get_events_containing_sub_string(const std::string& sub_string, const std::string& language) { - ilog("bookie plugin: get_events_containing_sub_string(${sub_string}, ${language})", (sub_string)(language)); + ilog("bookie plugin: get_events_containing_sub_string(${sub_string}, ${language})", + ("sub_string", sub_string)("language", language)); return my->get_events_containing_sub_string(sub_string, language); } diff --git a/libraries/plugins/bookie/include/graphene/bookie/bookie_api.hpp b/libraries/plugins/bookie/include/graphene/bookie/bookie_api.hpp index 36c8a64b..0919fc62 100644 --- a/libraries/plugins/bookie/include/graphene/bookie/bookie_api.hpp +++ b/libraries/plugins/bookie/include/graphene/bookie/bookie_api.hpp @@ -29,8 +29,8 @@ #include #include -#include -#include +#include +#include #include using namespace graphene::chain; diff --git a/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp b/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp index 1166ced3..bd91ef17 100644 --- a/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp +++ b/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp @@ -52,7 +52,7 @@ class persistent_event_object : public graphene::db::abstract_object persistent_event_id_type; +typedef object_id persistent_event_id_type; struct by_event_id; typedef multi_index_container< @@ -68,7 +68,8 @@ class events_by_competitor_index : public secondary_index public: virtual ~events_by_competitor_index() {} - virtual void object_inserted( const object& obj ) override; + virtual void object_loaded( const object& obj ) override; + virtual void object_created( const object& obj ) override; virtual void object_removed( const object& obj ) override; virtual void about_to_modify( const object& before ) override; virtual void object_modified( const object& after ) override; @@ -77,7 +78,12 @@ class events_by_competitor_index : public secondary_index map > competitor_to_events; }; -void events_by_competitor_index::object_inserted( const object& obj ) +void events_by_competitor_index::object_loaded( const object& obj ) +{ + object_created(obj); +} + +void events_by_competitor_index::object_created( const object& obj ) { const persistent_event_object& event_obj = *boost::polymorphic_downcast(&obj); for (const competitor_id_type& competitor_id : event_obj.competitors) @@ -97,7 +103,7 @@ void events_by_competitor_index::about_to_modify( const object& before ) } void events_by_competitor_index::object_modified( const object& after ) { - object_inserted(after); + object_created(after); } #endif diff --git a/libraries/plugins/bookie/include/graphene/bookie/bookie_plugin.hpp b/libraries/plugins/bookie/include/graphene/bookie/bookie_plugin.hpp index 333b8bab..93889cb8 100644 --- a/libraries/plugins/bookie/include/graphene/bookie/bookie_plugin.hpp +++ b/libraries/plugins/bookie/include/graphene/bookie/bookie_plugin.hpp @@ -23,8 +23,10 @@ */ #pragma once -#include #include +#include + +#include #include diff --git a/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp b/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp index 907d26ae..0965345e 100644 --- a/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp +++ b/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index 71de7db5..8ad490bc 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -23,7 +23,7 @@ */ #include -#include +#include #include #include diff --git a/libraries/plugins/es_objects/es_objects.cpp b/libraries/plugins/es_objects/es_objects.cpp index a2261d6a..8f92c391 100644 --- a/libraries/plugins/es_objects/es_objects.cpp +++ b/libraries/plugins/es_objects/es_objects.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include @@ -242,8 +242,8 @@ bool es_objects_plugin_impl::genesis() auto &idx = db.get_index_type(); idx.inspect_all_objects([this, &db](const graphene::db::object &o) { auto obj = db.find_object(o.id); - auto b = static_cast(obj); - prepareTemplate(*b, "transaction"); + auto b = static_cast(obj); + prepareTemplate(*b, "transaction"); }); } if (_es_objects_vesting_balance) { @@ -464,14 +464,14 @@ bool es_objects_plugin_impl::index_database(const vector& ids, s else prepareTemplate(*ba, "son_wallet_withdraw"); } - } else if (value.is() && _es_objects_transaction) { + } else if (value.is() && _es_objects_transaction) { auto obj = db.find_object(value); - auto ba = static_cast(obj); + auto ba = static_cast(obj); if (ba != nullptr) { if (action == "delete") remove_from_database(ba->id, "transaction"); else - prepareTemplate(*ba, "transaction"); + prepareTemplate(*ba, "transaction"); } } else if (value.is() && _es_objects_vesting_balance) { auto obj = db.find_object(value); @@ -756,4 +756,4 @@ void es_objects_plugin::plugin_startup() ilog("elasticsearch OBJECTS: plugin_startup() end"); } -} } \ No newline at end of file +} } diff --git a/libraries/plugins/generate_genesis/CMakeLists.txt b/libraries/plugins/generate_genesis/CMakeLists.txt index acc24202..318791a3 100644 --- a/libraries/plugins/generate_genesis/CMakeLists.txt +++ b/libraries/plugins/generate_genesis/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_generate_genesis generate_genesis.cpp ) -target_link_libraries( graphene_generate_genesis PRIVATE graphene_plugin ) +target_link_libraries( graphene_generate_genesis graphene_chain graphene_app ) target_include_directories( graphene_generate_genesis PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/generate_genesis/generate_genesis.cpp b/libraries/plugins/generate_genesis/generate_genesis.cpp index 88da427e..c526611f 100644 --- a/libraries/plugins/generate_genesis/generate_genesis.cpp +++ b/libraries/plugins/generate_genesis/generate_genesis.cpp @@ -296,12 +296,12 @@ void generate_genesis_plugin::generate_snapshot() auto balance_iter = by_effective_balance_index.begin(); for (; balance_iter != by_effective_balance_index.end(); ++balance_iter) { - fc::uint128 share_drop_amount = total_amount_to_distribute.value; + fc::uint128_t share_drop_amount = total_amount_to_distribute.value; share_drop_amount *= balance_iter->get_effective_balance().value; share_drop_amount /= total_bts_balance.value; - if (!share_drop_amount.to_uint64()) + if (!share_drop_amount) break; // balances are decreasing, so every balance after will also round to zero - total_shares_dropped += share_drop_amount.to_uint64(); + total_shares_dropped += share_drop_amount; effective_total_bts_balance += balance_iter->get_effective_balance(); } @@ -312,10 +312,10 @@ void generate_genesis_plugin::generate_snapshot() do { --balance_iter; - fc::uint128 share_drop_amount = remaining_amount_to_distribute.value; + fc::uint128_t share_drop_amount = remaining_amount_to_distribute.value; share_drop_amount *= balance_iter->get_effective_balance().value; share_drop_amount /= bts_balance_remaining.value; - graphene::chain::share_type amount_distributed = share_drop_amount.to_uint64(); + graphene::chain::share_type amount_distributed = share_drop_amount; by_effective_balance_index.modify(balance_iter, [&](my_account_balance_object& balance_object) { balance_object.sharedrop += amount_distributed; diff --git a/libraries/plugins/generate_uia_sharedrop_genesis/CMakeLists.txt b/libraries/plugins/generate_uia_sharedrop_genesis/CMakeLists.txt index 737e7614..a277e667 100644 --- a/libraries/plugins/generate_uia_sharedrop_genesis/CMakeLists.txt +++ b/libraries/plugins/generate_uia_sharedrop_genesis/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_generate_uia_sharedrop_genesis generate_uia_sharedrop_genesis.cpp ) -target_link_libraries( graphene_generate_uia_sharedrop_genesis PRIVATE graphene_plugin ) +target_link_libraries( graphene_generate_uia_sharedrop_genesis graphene_chain graphene_app ) target_include_directories( graphene_generate_uia_sharedrop_genesis PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp b/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp index b4d1254c..ad56e557 100644 --- a/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp +++ b/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp @@ -123,7 +123,6 @@ typedef multi_index_container< > > order_history_multi_index_type; - typedef generic_index bucket_index; typedef generic_index history_index; diff --git a/libraries/plugins/market_history/market_history_plugin.cpp b/libraries/plugins/market_history/market_history_plugin.cpp index 48c215f0..baa6c3c2 100644 --- a/libraries/plugins/market_history/market_history_plugin.cpp +++ b/libraries/plugins/market_history/market_history_plugin.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include diff --git a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_address.cpp b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_address.cpp index 69b28ee1..efc75df1 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_address.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_address.cpp @@ -209,8 +209,8 @@ bool btc_multisig_segwit_address::operator==(const btc_multisig_segwit_address & return true; } -std::vector btc_multisig_segwit_address::get_keys() { - std::vector keys; +std::vector btc_multisig_segwit_address::get_keys() { + std::vector keys; for (const auto &k : witnesses_keys) { keys.push_back(k.second); } diff --git a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp index fac29f5a..b90be034 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -180,7 +181,7 @@ void bitcoin_transaction_builder::add_out(payment_type type, int64_t amount, con const auto pubkey_bytes = bytes(pubkey.begin(), pubkey.begin() + pubkey.size()); add_out(type, amount, pubkey_bytes, front); } else { - const auto hash256 = fc::sha256::hash(pubkey.begin(), pubkey.size()); + const auto hash256 = fc::sha256::hash((const char*)pubkey.begin(), pubkey.size()); const auto hash160 = fc::ripemd160::hash(hash256.data(), hash256.data_size()); add_out(type, amount, bytes(hash160.data(), hash160.data() + hash160.data_size()), front); } diff --git a/libraries/plugins/peerplays_sidechain/hive/transaction.cpp b/libraries/plugins/peerplays_sidechain/hive/transaction.cpp index 3e4a59f5..d970b7cc 100644 --- a/libraries/plugins/peerplays_sidechain/hive/transaction.cpp +++ b/libraries/plugins/peerplays_sidechain/hive/transaction.cpp @@ -1,8 +1,9 @@ #include +#include + #include -#include #include namespace graphene { namespace peerplays_sidechain { namespace hive { @@ -32,8 +33,8 @@ void transaction::set_expiration(fc::time_point_sec expiration_time) { } void transaction::set_reference_block(const block_id_type &reference_block) { - ref_block_num = fc::endian_reverse_u32(reference_block._hash[0]); - ref_block_prefix = reference_block._hash[1]; + ref_block_num = protocol::block_header::num_from_id(reference_block); + ref_block_prefix = reference_block._hash[1].value(); } void signed_transaction::clear() { diff --git a/libraries/plugins/peerplays_sidechain/hive/types.cpp b/libraries/plugins/peerplays_sidechain/hive/types.cpp index 7a5506e7..bbf2e8c3 100644 --- a/libraries/plugins/peerplays_sidechain/hive/types.cpp +++ b/libraries/plugins/peerplays_sidechain/hive/types.cpp @@ -25,7 +25,7 @@ public_key_type::public_key_type(const std::string &base58str) { auto bin = fc::from_base58(base58str.substr(prefix_len)); auto bin_key = fc::raw::unpack(bin); key_data = bin_key.data; - FC_ASSERT(fc::ripemd160::hash(key_data.data, key_data.size())._hash[0] == bin_key.check); + FC_ASSERT(fc::ripemd160::hash((const char*)key_data.data(), key_data.size())._hash[0].value() == bin_key.check); }; public_key_type::operator fc::ecc::public_key_data() const { @@ -39,7 +39,7 @@ public_key_type::operator fc::ecc::public_key() const { public_key_type::operator std::string() const { binary_key k; k.data = key_data; - k.check = fc::ripemd160::hash(k.data.data, k.data.size())._hash[0]; + k.check = fc::ripemd160::hash((const char*)k.data.data(), k.data.size())._hash[0].value(); auto data = fc::raw::pack(k); return prefix + fc::to_base58(data.data(), data.size()); } diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/bitcoin_address.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/bitcoin_address.hpp index b9467e2f..4e6f251c 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/bitcoin_address.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/bitcoin_address.hpp @@ -3,7 +3,7 @@ #include #include -using namespace graphene::chain; +using namespace graphene::protocol; namespace graphene { namespace peerplays_sidechain { namespace bitcoin { @@ -126,7 +126,7 @@ public: return witness_script; } - std::vector get_keys(); + std::vector get_keys(); private: void create_witness_script(); @@ -217,6 +217,7 @@ public: private: void create_redeem_script(const fc::ecc::public_key &user_key_data, const std::vector> &keys_data); +public: uint32_t latency_; }; @@ -244,6 +245,8 @@ FC_REFLECT_DERIVED(graphene::peerplays_sidechain::bitcoin::btc_one_or_weighted_m (graphene::peerplays_sidechain::bitcoin::bitcoin_address), (redeem_script_)(witness_script_)); +/* It is not possible to reflect latency_ because it is private FC_REFLECT_DERIVED(graphene::peerplays_sidechain::bitcoin::btc_timelocked_one_or_weighted_multisig_address, (graphene::peerplays_sidechain::bitcoin::btc_one_or_weighted_multisig_address), (latency_)); +*/ diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/serialize.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/serialize.hpp index 2f1dfffe..60ab6c2f 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/serialize.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/serialize.hpp @@ -3,6 +3,8 @@ #include #include +#include + namespace graphene { namespace peerplays_sidechain { namespace bitcoin { inline void write_compact_size(bytes &vec, size_t size) { @@ -186,7 +188,7 @@ inline void pack(Stream &s, const bitcoin_transaction &tx, bool with_witness = t pack(s, out); if (flags & 1) { - for (const auto in : tx.vin) { + for (const auto& in : tx.vin) { pack_compact_size(s, in.scriptWitness.size()); for (const auto &sc : in.scriptWitness) pack(s, sc); @@ -294,13 +296,13 @@ inline void pack_tx_witness_signature(Stream &s, const std::vector &script { fc::datastream ps; - for (const auto in : tx.vin) + for (const auto& in : tx.vin) pack(ps, in.prevout); std::vector vec(ps.tellp()); if (vec.size()) { fc::datastream ds(vec.data(), size_t(vec.size())); - for (const auto in : tx.vin) + for (const auto& in : tx.vin) pack(ds, in.prevout); } @@ -309,13 +311,13 @@ inline void pack_tx_witness_signature(Stream &s, const std::vector &script { fc::datastream ps; - for (const auto in : tx.vin) + for (const auto& in : tx.vin) pack(ps, in.nSequence); std::vector vec(ps.tellp()); if (vec.size()) { fc::datastream ds(vec.data(), size_t(vec.size())); - for (const auto in : tx.vin) + for (const auto& in : tx.vin) pack(ds, in.nSequence); } @@ -324,13 +326,13 @@ inline void pack_tx_witness_signature(Stream &s, const std::vector &script { fc::datastream ps; - for (const auto out : tx.vout) + for (const auto& out : tx.vout) pack(ps, out); std::vector vec(ps.tellp()); if (vec.size()) { fc::datastream ds(vec.data(), size_t(vec.size())); - for (const auto out : tx.vout) + for (const auto& out : tx.vout) pack(ds, out); } diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.hpp index 41808562..365cbe4d 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.hpp @@ -6,7 +6,7 @@ namespace graphene { namespace peerplays_sidechain { namespace bitcoin { -class bitcoin_transaction; +struct bitcoin_transaction; const secp256k1_context_t *btc_context(); diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/types.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/types.hpp index 0997194b..659a568f 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/types.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin/types.hpp @@ -5,14 +5,14 @@ #include #include -#include +#include namespace graphene { namespace peerplays_sidechain { namespace bitcoin { -class bitcoin_transaction; +struct bitcoin_transaction; using bytes = std::vector; -using accounts_keys = std::map; +using accounts_keys = std::map; using full_btc_transaction = std::pair; enum class payment_type { diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp index 99c59019..409c6a01 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp @@ -1,5 +1,7 @@ #pragma once -#include +#include + +#include std::string object_id_to_string(graphene::chain::object_id_type id); diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp index 70618236..0abf7fe2 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp @@ -8,9 +8,9 @@ #include #include -#include -#include -#include +#include +#include +#include namespace graphene { namespace peerplays_sidechain { diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp index 1348ce35..64e9c564 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp @@ -5,7 +5,7 @@ #include -#include +#include #include #include #include diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp index f5b986e4..9a963879 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace graphene { namespace peerplays_sidechain { namespace hive { @@ -16,7 +17,7 @@ enum network { struct void_t {}; typedef fc::static_variant future_extensions; -typedef fc::flat_set extensions_type; +typedef future_extensions::flat_set_type extensions_type; typedef fc::ecc::private_key private_key_type; typedef fc::sha256 chain_id_type; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp index 9b08bc15..61c6d4d1 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp @@ -1,16 +1,18 @@ #pragma once +#include + +#include #include -#include -#include +#include #include -#include +#include -#include -#include +#include +#include namespace graphene { namespace peerplays_sidechain { diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp index a35c1933..56d193a6 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include + #include #include diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index 67a1783f..bd0bf866 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -5,11 +5,12 @@ #include #include + #include -#include #include #include #include +#include #include #include diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 1ad0d9c8..4f651b03 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -11,11 +11,12 @@ #include #include +#include #include -#include #include -#include #include +#include +#include #include #include #include diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp index 499f1e65..7abb72fa 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp @@ -14,14 +14,13 @@ #include #include #include -#include #include #include -#include -#include -#include #include +#include +#include +#include #include #include #include diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp index d5a9ec32..9e968421 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp @@ -11,13 +11,14 @@ #include #include #include -#include +#include +#include +#include #include -#include -#include -#include #include +#include +#include #include namespace graphene { namespace peerplays_sidechain { diff --git a/libraries/plugins/witness/include/graphene/witness/witness.hpp b/libraries/plugins/witness/include/graphene/witness/witness.hpp index f0c3ece7..9ec5a02c 100644 --- a/libraries/plugins/witness/include/graphene/witness/witness.hpp +++ b/libraries/plugins/witness/include/graphene/witness/witness.hpp @@ -79,7 +79,6 @@ private: boost::program_options::variables_map _options; bool _production_enabled = false; - bool _consecutive_production_enabled = false; uint32_t _required_witness_participation = 33 * GRAPHENE_1_PERCENT; uint32_t _production_skip_flags = graphene::chain::database::skip_nothing; diff --git a/libraries/protocol/CMakeLists.txt b/libraries/protocol/CMakeLists.txt new file mode 100644 index 00000000..a3006b5e --- /dev/null +++ b/libraries/protocol/CMakeLists.txt @@ -0,0 +1,62 @@ +file(GLOB HEADERS "include/graphene/protocol/*.hpp") + +list(APPEND SOURCES account.cpp + assert.cpp + asset_ops.cpp + block.cpp + confidential.cpp + chain_parameters.cpp + fee_schedule.cpp + memo.cpp + proposal.cpp + transfer.cpp + vote.cpp + witness.cpp + address.cpp + asset.cpp + authority.cpp + special_authority.cpp + committee_member.cpp + custom.cpp + market.cpp + operations.cpp + pts_address.cpp + small_ops.cpp + transaction.cpp + types.cpp + withdraw_permission.cpp + worker.cpp + betting_market.cpp + event.cpp + event_group.cpp + lottery_ops.cpp + small_ops.cpp + sport.cpp + tournament.cpp + small_ops.cpp + custom_permission.cpp + custom_account_authority.cpp + offer.cpp + nft.cpp + nft_lottery.cpp + account_role.cpp + ) + + +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_protocol ${SOURCES} ${HEADERS} ) +else() + add_library( graphene_protocol SHARED ${SOURCES} ${HEADERS} ) +endif() + +target_link_libraries( graphene_protocol fc ) +target_include_directories( graphene_protocol PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + +install( TARGETS + graphene_protocol + + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) +install( FILES ${HEADERS} DESTINATION "include/graphene/protocol" ) diff --git a/libraries/chain/protocol/account.cpp b/libraries/protocol/account.cpp similarity index 87% rename from libraries/chain/protocol/account.cpp rename to libraries/protocol/account.cpp index 2405369a..018cb480 100644 --- a/libraries/chain/protocol/account.cpp +++ b/libraries/protocol/account.cpp @@ -21,13 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include +#include + #include -#include - -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * Names must comply with the following grammar (RFC 1035): @@ -63,13 +61,6 @@ bool is_valid_name( const string& name ) { try { const size_t len = name.size(); - /** this condition will prevent witnesses from including new names before this time, but - * allow them after this time. This check can be removed from the code after HARDFORK_385_TIME - * has passed. - */ - if( fc::time_point::now() < fc::time_point(HARDFORK_385_TIME) ) - FC_ASSERT( len >= 3 ); - if( len < GRAPHENE_MIN_ACCOUNT_NAME_LENGTH ) { ilog( "."); @@ -329,16 +320,17 @@ void account_transfer_operation::validate()const } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_options ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_whitelist_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_upgrade_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_transfer_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_whitelist_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_upgrade_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::account_transfer_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_options ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_whitelist_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_upgrade_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_transfer_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_whitelist_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_upgrade_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::account_transfer_operation ) diff --git a/libraries/chain/protocol/account_role.cpp b/libraries/protocol/account_role.cpp similarity index 94% rename from libraries/chain/protocol/account_role.cpp rename to libraries/protocol/account_role.cpp index 1d71d6cc..1f52f7d2 100644 --- a/libraries/chain/protocol/account_role.cpp +++ b/libraries/protocol/account_role.cpp @@ -1,9 +1,9 @@ -#include -#include +#include +#include namespace graphene { - namespace chain + namespace protocol { void account_role_create_operation::validate() const @@ -57,5 +57,5 @@ namespace graphene return k.fee + calculate_data_fee(fc::raw::pack_size(*this), k.price_per_kbyte); } - } // namespace chain + } // namespace protocol } // namespace graphene diff --git a/libraries/chain/protocol/address.cpp b/libraries/protocol/address.cpp similarity index 70% rename from libraries/chain/protocol/address.cpp rename to libraries/protocol/address.cpp index f0edbd49..660fe6f0 100644 --- a/libraries/chain/protocol/address.cpp +++ b/libraries/protocol/address.cpp @@ -21,17 +21,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include -#include +#include +#include #include #include #include -namespace graphene { - namespace chain { - +namespace graphene { namespace protocol { address::address( const std::string& base58str ) { std::string prefix( GRAPHENE_ADDRESS_PREFIX ); @@ -71,7 +68,7 @@ namespace graphene { address::address( const fc::ecc::public_key& pub ) { auto dat = pub.serialize(); - addr = fc::ripemd160::hash( fc::sha512::hash( dat.data, sizeof( dat ) ) ); + addr = fc::ripemd160::hash( fc::sha512::hash( (char*) dat.data(), dat.size() ) ); } address::address( const pts_address& ptsaddr ) @@ -81,35 +78,37 @@ namespace graphene { address::address( const fc::ecc::public_key_data& pub ) { - addr = fc::ripemd160::hash( fc::sha512::hash( pub.data, sizeof( pub ) ) ); + addr = fc::ripemd160::hash( fc::sha512::hash( (char*) pub.data(), pub.size() ) ); } - address::address( const graphene::chain::public_key_type& pub ) + address::address( const graphene::protocol::public_key_type& pub ) { - addr = fc::ripemd160::hash( fc::sha512::hash( pub.key_data.data, sizeof( pub.key_data ) ) ); + addr = fc::ripemd160::hash( fc::sha512::hash( (char*) pub.key_data.data(), pub.key_data.size() ) ); } address::operator std::string()const { - fc::array bin_addr; - memcpy( (char*)&bin_addr, (char*)&addr, sizeof( addr ) ); - auto checksum = fc::ripemd160::hash( (char*)&addr, sizeof( addr ) ); - memcpy( ((char*)&bin_addr)+20, (char*)&checksum._hash[0], 4 ); - return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( bin_addr.data, sizeof( bin_addr ) ); + std::array bin_addr; + static_assert( bin_addr.size() >= sizeof(addr) + 4, "" ); + memcpy( bin_addr.data(), addr.data(), sizeof(addr) ); + auto checksum = fc::ripemd160::hash( addr.data(), sizeof(addr) ); + memcpy( bin_addr.data() + 20, (char*)&checksum._hash[0], 4 ); + return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( bin_addr.data(), bin_addr.size() ); } -} } // namespace graphene::chain +} } // namespace graphene::protocol namespace fc { - void to_variant( const graphene::chain::address& var, variant& vo, uint32_t max_depth ) + void to_variant( const graphene::protocol::address& var, variant& vo, uint32_t max_depth ) { vo = std::string(var); } - void from_variant( const variant& var, graphene::chain::address& vo, uint32_t max_depth ) + void from_variant( const variant& var, graphene::protocol::address& vo, uint32_t max_depth ) { - vo = graphene::chain::address( var.as_string() ); + vo = graphene::protocol::address( var.as_string() ); } } -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::address ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::address ) + diff --git a/libraries/chain/protocol/assert.cpp b/libraries/protocol/assert.cpp similarity index 82% rename from libraries/chain/protocol/assert.cpp rename to libraries/protocol/assert.cpp index 5ce61e45..27f7f85b 100644 --- a/libraries/chain/protocol/assert.cpp +++ b/libraries/protocol/assert.cpp @@ -21,13 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include -#include +#include +#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { bool account_name_eq_lit_predicate::validate()const { @@ -66,7 +66,8 @@ share_type assert_operation::calculate_fee(const fee_parameters_type& k)const return k.fee * predicates.size(); } -} } // namespace graphene::chain +} } // namespace graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::assert_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::assert_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::assert_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::assert_operation ) diff --git a/libraries/chain/protocol/asset.cpp b/libraries/protocol/asset.cpp similarity index 95% rename from libraries/chain/protocol/asset.cpp rename to libraries/protocol/asset.cpp index 525e193b..de72d5bb 100644 --- a/libraries/chain/protocol/asset.cpp +++ b/libraries/protocol/asset.cpp @@ -21,12 +21,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include #include #include #include +#include -namespace graphene { namespace chain { +#include + +namespace graphene { namespace protocol { typedef boost::multiprecision::uint128_t uint128_t; typedef boost::multiprecision::int128_t int128_t; @@ -206,8 +209,9 @@ const int64_t scaled_precision_lut[19] = p10< 16 >::v, p10< 17 >::v, p10< 18 >::v }; -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::price ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::price_feed ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::price ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::price_feed ) diff --git a/libraries/chain/protocol/asset_ops.cpp b/libraries/protocol/asset_ops.cpp similarity index 75% rename from libraries/chain/protocol/asset_ops.cpp rename to libraries/protocol/asset_ops.cpp index 5dfd09ee..df8e38ec 100644 --- a/libraries/chain/protocol/asset_ops.cpp +++ b/libraries/protocol/asset_ops.cpp @@ -21,12 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * Valid symbols can contain [A-Z0-9], and '.' @@ -289,31 +288,32 @@ void lottery_asset_options::validate() const FC_ASSERT( total == GRAPHENE_100_PERCENT, "distribution amount not equals GRAPHENE_100_PERCENT" ); } -} } // namespace graphene::chain +} } // namespace graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_options ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::bitasset_options ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_global_settle_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_settle_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_fund_fee_pool_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_claim_fees_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_update_bitasset_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_update_feed_producers_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_publish_feed_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_issue_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_reserve_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_global_settle_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_settle_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_settle_cancel_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_fund_fee_pool_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_claim_fees_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_dividend_distribution_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_update_bitasset_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_update_feed_producers_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_publish_feed_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_issue_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::asset_reserve_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_options ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::bitasset_options ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_global_settle_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_settle_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_fund_fee_pool_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_claim_fees_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_update_bitasset_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_update_feed_producers_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_publish_feed_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_issue_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_reserve_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_global_settle_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_settle_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_settle_cancel_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_fund_fee_pool_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_claim_fees_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_dividend_distribution_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_update_bitasset_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_update_feed_producers_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_publish_feed_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_issue_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::asset_reserve_operation ) diff --git a/libraries/chain/protocol/authority.cpp b/libraries/protocol/authority.cpp similarity index 87% rename from libraries/chain/protocol/authority.cpp rename to libraries/protocol/authority.cpp index 6cfed2ec..47fc29b4 100644 --- a/libraries/chain/protocol/authority.cpp +++ b/libraries/protocol/authority.cpp @@ -22,10 +22,11 @@ * THE SOFTWARE. */ -#include +#include + #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void add_authority_accounts( flat_set& result, @@ -36,6 +37,7 @@ void add_authority_accounts( result.insert( item.first ); } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::authority ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::authority ) diff --git a/libraries/chain/protocol/betting_market.cpp b/libraries/protocol/betting_market.cpp similarity index 94% rename from libraries/chain/protocol/betting_market.cpp rename to libraries/protocol/betting_market.cpp index 99712f9c..a27b3dc7 100644 --- a/libraries/chain/protocol/betting_market.cpp +++ b/libraries/protocol/betting_market.cpp @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void betting_market_rules_create_operation::validate() const { @@ -77,5 +77,5 @@ void bet_cancel_operation::validate() const -} } // graphene::chain +} } // graphene::protocol diff --git a/libraries/chain/protocol/block.cpp b/libraries/protocol/block.cpp similarity index 83% rename from libraries/chain/protocol/block.cpp rename to libraries/protocol/block.cpp index 725ea3a7..6bd79e7f 100644 --- a/libraries/chain/protocol/block.cpp +++ b/libraries/protocol/block.cpp @@ -21,13 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include +#include #include -#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { digest_type block_header::digest()const { return digest_type::hash(*this); @@ -35,13 +33,13 @@ namespace graphene { namespace chain { uint32_t block_header::num_from_id(const block_id_type& id) { - return fc::endian_reverse_u32(id._hash[0]); + return boost::endian::endian_reverse(id._hash[0].value()); } block_id_type signed_block_header::id()const { auto tmp = fc::sha224::hash( *this ); - tmp._hash[0] = fc::endian_reverse_u32(block_num()); // store the block num in the ID, 160 bits is plenty for the hash + tmp._hash[0] = boost::endian::endian_reverse(block_num()); // store the block num in the ID, 160 bits is plenty for the hash static_assert( sizeof(tmp._hash[0]) == 4, "should be 4 bytes" ); block_id_type result; memcpy(result._hash, tmp._hash, std::min(sizeof(result), sizeof(tmp))); @@ -92,6 +90,7 @@ namespace graphene { namespace chain { } } -GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::block_header) -GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::signed_block_header) -GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::signed_block) +GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::protocol::block_header) +GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::protocol::signed_block_header) +GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::protocol::signed_block) + diff --git a/libraries/chain/protocol/chain_parameters.cpp b/libraries/protocol/chain_parameters.cpp similarity index 96% rename from libraries/chain/protocol/chain_parameters.cpp rename to libraries/protocol/chain_parameters.cpp index a904b0e3..9e4fd440 100644 --- a/libraries/chain/protocol/chain_parameters.cpp +++ b/libraries/protocol/chain_parameters.cpp @@ -1,7 +1,7 @@ -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { chain_parameters::chain_parameters() { current_fees = std::make_shared(); } diff --git a/libraries/chain/protocol/committee_member.cpp b/libraries/protocol/committee_member.cpp similarity index 65% rename from libraries/chain/protocol/committee_member.cpp rename to libraries/protocol/committee_member.cpp index 3ce62783..43f0eb04 100644 --- a/libraries/chain/protocol/committee_member.cpp +++ b/libraries/protocol/committee_member.cpp @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include +#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void committee_member_create_operation::validate()const { @@ -47,11 +47,12 @@ void committee_member_update_global_parameters_operation::validate() const new_parameters.validate(); } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::committee_member_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::committee_member_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::committee_member_update_global_parameters_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::committee_member_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::committee_member_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::committee_member_update_global_parameters_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::committee_member_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::committee_member_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::committee_member_update_global_parameters_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::committee_member_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::committee_member_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::committee_member_update_global_parameters_operation ) diff --git a/libraries/chain/protocol/confidential.cpp b/libraries/protocol/confidential.cpp similarity index 86% rename from libraries/chain/protocol/confidential.cpp rename to libraries/protocol/confidential.cpp index 2e8fbc68..f7d03f58 100644 --- a/libraries/chain/protocol/confidential.cpp +++ b/libraries/protocol/confidential.cpp @@ -21,14 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include -#include + +#include #include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void transfer_to_blind_operation::validate()const { @@ -155,11 +154,12 @@ stealth_confirmation::stealth_confirmation( const std::string& base58 ) *this = fc::raw::unpack( fc::from_base58( base58 ) ); } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::transfer_to_blind_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::transfer_from_blind_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::blind_transfer_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::transfer_to_blind_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::transfer_from_blind_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::blind_transfer_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::transfer_to_blind_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::transfer_from_blind_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::blind_transfer_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::transfer_to_blind_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::transfer_from_blind_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::blind_transfer_operation ) diff --git a/libraries/chain/protocol/custom.cpp b/libraries/protocol/custom.cpp similarity index 82% rename from libraries/chain/protocol/custom.cpp rename to libraries/protocol/custom.cpp index 72f8dd44..7f0773e6 100644 --- a/libraries/chain/protocol/custom.cpp +++ b/libraries/protocol/custom.cpp @@ -21,11 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include -#include - -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void custom_operation::validate()const { @@ -38,5 +36,6 @@ share_type custom_operation::calculate_fee(const fee_parameters_type& k)const } } -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::custom_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::custom_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::custom_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::custom_operation ) + diff --git a/libraries/chain/protocol/custom_account_authority.cpp b/libraries/protocol/custom_account_authority.cpp similarity index 92% rename from libraries/chain/protocol/custom_account_authority.cpp rename to libraries/protocol/custom_account_authority.cpp index a74234d7..eaf939bc 100644 --- a/libraries/chain/protocol/custom_account_authority.cpp +++ b/libraries/protocol/custom_account_authority.cpp @@ -1,9 +1,9 @@ -#include -#include +#include +#include namespace graphene { -namespace chain +namespace protocol { void custom_account_authority_create_operation::validate() const @@ -39,5 +39,5 @@ share_type custom_account_authority_create_operation::calculate_fee(const fee_pa return k.fee + calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte ); } -} // namespace chain +} // namespace protocol } // namespace graphene diff --git a/libraries/chain/protocol/custom_permission.cpp b/libraries/protocol/custom_permission.cpp similarity index 95% rename from libraries/chain/protocol/custom_permission.cpp rename to libraries/protocol/custom_permission.cpp index c0919cbd..5084bf0b 100644 --- a/libraries/chain/protocol/custom_permission.cpp +++ b/libraries/protocol/custom_permission.cpp @@ -1,9 +1,9 @@ -#include -#include +#include +#include namespace graphene { -namespace chain +namespace protocol { bool is_valid_permission_name(const string &name) @@ -81,5 +81,5 @@ share_type custom_permission_create_operation::calculate_fee(const fee_parameter return k.fee + calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte ); } -} // namespace chain +} // namespace protocol } // namespace graphene diff --git a/libraries/chain/protocol/event.cpp b/libraries/protocol/event.cpp similarity index 93% rename from libraries/chain/protocol/event.cpp rename to libraries/protocol/event.cpp index 730e3fb6..7b492270 100644 --- a/libraries/chain/protocol/event.cpp +++ b/libraries/protocol/event.cpp @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void event_create_operation::validate() const { @@ -40,5 +40,5 @@ void event_update_status_operation::validate() const FC_ASSERT( fee.amount >= 0 ); } -} } // graphene::chain +} } // graphene::protocol diff --git a/libraries/chain/protocol/event_group.cpp b/libraries/protocol/event_group.cpp similarity index 92% rename from libraries/chain/protocol/event_group.cpp rename to libraries/protocol/event_group.cpp index 39fe0f3c..dfa0a904 100644 --- a/libraries/chain/protocol/event_group.cpp +++ b/libraries/protocol/event_group.cpp @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void event_group_create_operation::validate() const { @@ -40,5 +40,5 @@ void event_group_delete_operation::validate() const FC_ASSERT( fee.amount >= 0 ); } -} } // graphene::chain +} } // graphene::protocol diff --git a/libraries/chain/protocol/fee_schedule.cpp b/libraries/protocol/fee_schedule.cpp similarity index 94% rename from libraries/chain/protocol/fee_schedule.cpp rename to libraries/protocol/fee_schedule.cpp index 122136ea..cf653462 100644 --- a/libraries/chain/protocol/fee_schedule.cpp +++ b/libraries/protocol/fee_schedule.cpp @@ -22,13 +22,14 @@ * THE SOFTWARE. */ #include -#include +#include #include +#include #define MAX_FEE_STABILIZATION_ITERATION 4 -namespace graphene { namespace chain { +namespace graphene { namespace protocol { fee_schedule::fee_schedule() { @@ -116,14 +117,14 @@ namespace graphene { namespace chain { auto itr = parameters.find(params); if( itr != parameters.end() ) params = *itr; auto base_value = op.visit( calc_fee_visitor( params ) ); - auto scaled = fc::uint128(base_value) * scale; + auto scaled = fc::uint128_t(base_value) * scale; scaled /= GRAPHENE_100_PERCENT; FC_ASSERT( scaled <= GRAPHENE_MAX_SHARE_SUPPLY ); //idump( (base_value)(scaled)(core_exchange_rate) ); - auto result = asset( scaled.to_uint64(), asset_id_type(0) ) * core_exchange_rate; + auto result = asset( scaled, asset_id_type(0) ) * core_exchange_rate; //FC_ASSERT( result * core_exchange_rate >= asset( scaled.to_uint64()) ); - while( result * core_exchange_rate < asset( scaled.to_uint64()) ) + while( result * core_exchange_rate < asset(scaled) ) result.amount++; FC_ASSERT( result.amount <= GRAPHENE_MAX_SHARE_SUPPLY ); @@ -194,6 +195,7 @@ namespace graphene { namespace chain { } } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::fee_schedule ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::fee_schedule ) diff --git a/libraries/chain/include/graphene/chain/protocol/README.md b/libraries/protocol/include/graphene/protocol/README.md similarity index 100% rename from libraries/chain/include/graphene/chain/protocol/README.md rename to libraries/protocol/include/graphene/protocol/README.md diff --git a/libraries/chain/include/graphene/chain/protocol/account.hpp b/libraries/protocol/include/graphene/protocol/account.hpp similarity index 79% rename from libraries/chain/include/graphene/chain/protocol/account.hpp rename to libraries/protocol/include/graphene/protocol/account.hpp index 50ccb8ae..f5b1f976 100644 --- a/libraries/chain/include/graphene/chain/protocol/account.hpp +++ b/libraries/protocol/include/graphene/protocol/account.hpp @@ -22,14 +22,15 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include -#include -#include -#include -namespace graphene { namespace chain { +#include +#include +#include +#include +#include +#include + +namespace graphene { namespace protocol { bool is_valid_name( const string& s ); bool is_cheap_name( const string& n ); @@ -287,49 +288,51 @@ namespace graphene { namespace chain { void validate()const; }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT(graphene::chain::account_options, (memo_key)(voting_account)(num_witness)(num_committee)(votes)(extensions)) -// FC_REFLECT_TYPENAME( graphene::chain::account_whitelist_operation::account_listing) -FC_REFLECT_ENUM( graphene::chain::account_whitelist_operation::account_listing, +FC_REFLECT(graphene::protocol::account_options, (memo_key)(voting_account)(num_witness)(num_committee)(votes)(extensions)) +FC_REFLECT_ENUM( graphene::protocol::account_whitelist_operation::account_listing, (no_listing)(white_listed)(black_listed)(white_and_black_listed)) -FC_REFLECT_ENUM( graphene::chain::app_tag, (bookie)(rps) ) -FC_REFLECT( graphene::chain::affiliate_reward_distribution, (_dist) ); -FC_REFLECT( graphene::chain::affiliate_reward_distributions, (_dists) ); +FC_REFLECT_ENUM( graphene::protocol::app_tag, (bookie)(rps) ) +FC_REFLECT( graphene::protocol::affiliate_reward_distribution, (_dist) ); +FC_REFLECT( graphene::protocol::affiliate_reward_distributions, (_dists) ); -FC_REFLECT(graphene::chain::account_create_operation::ext, (null_ext)(owner_special_authority)(active_special_authority)(buyback_options) ) -FC_REFLECT( graphene::chain::account_create_operation, +FC_REFLECT(graphene::protocol::account_create_operation::ext, (null_ext)(owner_special_authority)(active_special_authority)(buyback_options)(affiliate_distributions) ) +FC_REFLECT_TYPENAME(graphene::protocol::extension) +FC_REFLECT( graphene::protocol::account_create_operation, (fee)(registrar) (referrer)(referrer_percent) (name)(owner)(active)(options)(extensions) ) -FC_REFLECT(graphene::chain::account_update_operation::ext, (null_ext)(owner_special_authority)(active_special_authority)(update_last_voting_time) ) -FC_REFLECT( graphene::chain::account_update_operation, +FC_REFLECT(graphene::protocol::account_update_operation::ext, (null_ext)(owner_special_authority)(active_special_authority)(update_last_voting_time) ) +FC_REFLECT_TYPENAME(graphene::protocol::extension) +FC_REFLECT( graphene::protocol::account_update_operation, (fee)(account)(owner)(active)(new_options)(extensions) ) -FC_REFLECT( graphene::chain::account_upgrade_operation, +FC_REFLECT( graphene::protocol::account_upgrade_operation, (fee)(account_to_upgrade)(upgrade_to_lifetime_member)(extensions) ) -FC_REFLECT( graphene::chain::account_whitelist_operation, (fee)(authorizing_account)(account_to_list)(new_listing)(extensions)) +FC_REFLECT( graphene::protocol::account_whitelist_operation, (fee)(authorizing_account)(account_to_list)(new_listing)(extensions)) -FC_REFLECT( graphene::chain::account_create_operation::fee_parameters_type, (basic_fee)(premium_fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::account_whitelist_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::account_update_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::account_upgrade_operation::fee_parameters_type, (membership_annual_fee)(membership_lifetime_fee) ) -FC_REFLECT( graphene::chain::account_transfer_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::account_transfer_operation, (fee)(account_id)(new_owner)(extensions) ) +FC_REFLECT( graphene::protocol::account_create_operation::fee_parameters_type, (basic_fee)(premium_fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::account_whitelist_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::account_update_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::account_upgrade_operation::fee_parameters_type, (membership_annual_fee)(membership_lifetime_fee) ) +FC_REFLECT( graphene::protocol::account_transfer_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::account_transfer_operation, (fee)(account_id)(new_owner)(extensions) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_options ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_whitelist_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_upgrade_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_transfer_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_whitelist_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_upgrade_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::account_transfer_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_options ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_whitelist_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_upgrade_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_transfer_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_whitelist_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_upgrade_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::account_transfer_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/account_role.hpp b/libraries/protocol/include/graphene/protocol/account_role.hpp similarity index 71% rename from libraries/chain/include/graphene/chain/protocol/account_role.hpp rename to libraries/protocol/include/graphene/protocol/account_role.hpp index 6a532cb7..62c302f7 100644 --- a/libraries/chain/include/graphene/chain/protocol/account_role.hpp +++ b/libraries/protocol/include/graphene/protocol/account_role.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include +#include namespace graphene { - namespace chain + namespace protocol { struct account_role_create_operation : public base_operation @@ -70,13 +70,13 @@ namespace graphene void validate() const; share_type calculate_fee(const fee_parameters_type &k) const { return k.fee; } }; - } // namespace chain + } // namespace protocol } // namespace graphene -FC_REFLECT(graphene::chain::account_role_create_operation::fee_parameters_type, (fee)(price_per_kbyte)) -FC_REFLECT(graphene::chain::account_role_update_operation::fee_parameters_type, (fee)(price_per_kbyte)) -FC_REFLECT(graphene::chain::account_role_delete_operation::fee_parameters_type, (fee)) +FC_REFLECT(graphene::protocol::account_role_create_operation::fee_parameters_type, (fee)(price_per_kbyte)) +FC_REFLECT(graphene::protocol::account_role_update_operation::fee_parameters_type, (fee)(price_per_kbyte)) +FC_REFLECT(graphene::protocol::account_role_delete_operation::fee_parameters_type, (fee)) -FC_REFLECT(graphene::chain::account_role_create_operation, (fee)(owner)(name)(metadata)(allowed_operations)(whitelisted_accounts)(valid_to)(extensions)) -FC_REFLECT(graphene::chain::account_role_update_operation, (fee)(owner)(account_role_id)(name)(metadata)(allowed_operations_to_add)(allowed_operations_to_remove)(accounts_to_add)(accounts_to_remove)(valid_to)(extensions)) -FC_REFLECT(graphene::chain::account_role_delete_operation, (fee)(owner)(account_role_id)(owner)(extensions)) +FC_REFLECT(graphene::protocol::account_role_create_operation, (fee)(owner)(name)(metadata)(allowed_operations)(whitelisted_accounts)(valid_to)(extensions)) +FC_REFLECT(graphene::protocol::account_role_update_operation, (fee)(owner)(account_role_id)(name)(metadata)(allowed_operations_to_add)(allowed_operations_to_remove)(accounts_to_add)(accounts_to_remove)(valid_to)(extensions)) +FC_REFLECT(graphene::protocol::account_role_delete_operation, (fee)(owner)(account_role_id)(owner)(extensions)) diff --git a/libraries/chain/include/graphene/chain/protocol/address.hpp b/libraries/protocol/include/graphene/protocol/address.hpp similarity index 77% rename from libraries/chain/include/graphene/chain/protocol/address.hpp rename to libraries/protocol/include/graphene/protocol/address.hpp index 8bf0fab6..5b2587a1 100644 --- a/libraries/chain/include/graphene/chain/protocol/address.hpp +++ b/libraries/protocol/include/graphene/protocol/address.hpp @@ -23,16 +23,14 @@ */ #pragma once -#include -#include -#include +#include +#include #include #include -namespace graphene { namespace chain { - - struct public_key_type; +namespace graphene { namespace protocol { + struct pts_address; /** * @brief a 160 bit hash of a public key @@ -70,28 +68,15 @@ namespace graphene { namespace chain { inline bool operator != ( const address& a, const address& b ) { return a.addr != b.addr; } inline bool operator < ( const address& a, const address& b ) { return a.addr < b.addr; } -} } // namespace graphene::chain +} } // namespace graphene::protocol namespace fc { - void to_variant( const graphene::chain::address& var, fc::variant& vo, uint32_t max_depth = 1 ); - void from_variant( const fc::variant& var, graphene::chain::address& vo, uint32_t max_depth = 1 ); + void to_variant( const graphene::protocol::address& var, fc::variant& vo, uint32_t max_depth = 1 ); + void from_variant( const fc::variant& var, graphene::protocol::address& vo, uint32_t max_depth = 1 ); } -namespace std -{ - template<> - struct hash - { - public: - size_t operator()(const graphene::chain::address &a) const - { - return (uint64_t(a.addr._hash[0])<<32) | uint64_t( a.addr._hash[0] ); - } - }; -} +FC_REFLECT( graphene::protocol::address, (addr) ) -#include -FC_REFLECT( graphene::chain::address, (addr) ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::address ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::address ) diff --git a/libraries/chain/include/graphene/chain/protocol/affiliate.hpp b/libraries/protocol/include/graphene/protocol/affiliate.hpp similarity index 82% rename from libraries/chain/include/graphene/chain/protocol/affiliate.hpp rename to libraries/protocol/include/graphene/protocol/affiliate.hpp index b2c3ee88..15509ee0 100644 --- a/libraries/chain/include/graphene/chain/protocol/affiliate.hpp +++ b/libraries/protocol/include/graphene/protocol/affiliate.hpp @@ -22,11 +22,13 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include -namespace graphene { namespace chain { +#include +#include +#include +#include + +namespace graphene { namespace protocol { /** * Virtual op generated when an affiliate receives payout. @@ -83,10 +85,10 @@ namespace graphene { namespace chain { { return 0; } }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::affiliate_payout_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::affiliate_referral_payout_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::affiliate_payout_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::affiliate_referral_payout_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::affiliate_payout_operation, (fee)(affiliate)(tag)(payout) ) -FC_REFLECT( graphene::chain::affiliate_referral_payout_operation, (fee)(player)(payout) ) +FC_REFLECT( graphene::protocol::affiliate_payout_operation, (fee)(affiliate)(tag)(payout) ) +FC_REFLECT( graphene::protocol::affiliate_referral_payout_operation, (fee)(player)(payout) ) diff --git a/libraries/chain/include/graphene/chain/protocol/assert.hpp b/libraries/protocol/include/graphene/protocol/assert.hpp similarity index 80% rename from libraries/chain/include/graphene/chain/protocol/assert.hpp rename to libraries/protocol/include/graphene/protocol/assert.hpp index ce758862..7c277893 100644 --- a/libraries/chain/include/graphene/chain/protocol/assert.hpp +++ b/libraries/protocol/include/graphene/protocol/assert.hpp @@ -22,10 +22,11 @@ * THE SOFTWARE. */ #pragma once -#include -#include -namespace graphene { namespace chain { +#include +#include + +namespace graphene { namespace protocol { /** * Used to verify that account_id->name is equal to the given string literal. @@ -104,14 +105,15 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const; }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::assert_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::account_name_eq_lit_predicate, (account_id)(name) ) -FC_REFLECT( graphene::chain::asset_symbol_eq_lit_predicate, (asset_id)(symbol) ) -FC_REFLECT( graphene::chain::block_id_predicate, (id) ) -FC_REFLECT_TYPENAME( graphene::chain::predicate ) -FC_REFLECT( graphene::chain::assert_operation, (fee)(fee_paying_account)(predicates)(required_auths)(extensions) ) +FC_REFLECT( graphene::protocol::assert_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::account_name_eq_lit_predicate, (account_id)(name) ) +FC_REFLECT( graphene::protocol::asset_symbol_eq_lit_predicate, (asset_id)(symbol) ) +FC_REFLECT( graphene::protocol::block_id_predicate, (id) ) +FC_REFLECT_TYPENAME( graphene::protocol::predicate ) +FC_REFLECT( graphene::protocol::assert_operation, (fee)(fee_paying_account)(predicates)(required_auths)(extensions) ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::assert_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::assert_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::assert_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::assert_operation ) + diff --git a/libraries/chain/include/graphene/chain/protocol/asset.hpp b/libraries/protocol/include/graphene/protocol/asset.hpp similarity index 94% rename from libraries/chain/include/graphene/chain/protocol/asset.hpp rename to libraries/protocol/include/graphene/protocol/asset.hpp index 60bd3cd0..565da6a4 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset.hpp +++ b/libraries/protocol/include/graphene/protocol/asset.hpp @@ -22,10 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { extern const int64_t scaled_precision_lut[]; @@ -211,14 +210,15 @@ namespace graphene { namespace chain { } } -FC_REFLECT( graphene::chain::asset, (amount)(asset_id) ) -FC_REFLECT( graphene::chain::price, (base)(quote) ) +FC_REFLECT( graphene::protocol::asset, (amount)(asset_id) ) +FC_REFLECT( graphene::protocol::price, (base)(quote) ) #define GRAPHENE_PRICE_FEED_FIELDS (settlement_price)(maintenance_collateral_ratio)(maximum_short_squeeze_ratio) \ (core_exchange_rate) -FC_REFLECT( graphene::chain::price_feed, GRAPHENE_PRICE_FEED_FIELDS ) +FC_REFLECT( graphene::protocol::price_feed, GRAPHENE_PRICE_FEED_FIELDS ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::price ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::price_feed ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::price ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::price_feed ) diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/protocol/include/graphene/protocol/asset_ops.hpp similarity index 82% rename from libraries/chain/include/graphene/chain/protocol/asset_ops.hpp rename to libraries/protocol/include/graphene/protocol/asset_ops.hpp index ae5dc211..6498e71d 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/protocol/include/graphene/protocol/asset_ops.hpp @@ -22,12 +22,11 @@ * THE SOFTWARE. */ #pragma once -#include -#include - -namespace graphene { namespace chain { - class database; +#include +#include +#include +namespace graphene { namespace protocol { bool is_valid_symbol( const string& symbol ); struct benefactor { @@ -152,13 +151,13 @@ namespace graphene { namespace chain { /// the options are updated again. fc::optional payout_interval; /// Each dividend distribution incurs a fee that is based on the number of accounts - /// that hold the dividend asset, not as a percentage of the amount paid out. + /// that hold the dividend asset, not as a percentage of the amount paid out. /// This parameter prevents assets from being distributed unless the fee is less than /// the percentage here, to prevent a slow trickle of deposits to the account from being /// completely consumed. /// In other words, if you set this parameter to 10% and the fees work out to 100 BTS /// to share out, balances in the dividend distribution accounts will not be shared out - /// if the balance is less than 10000 BTS. + /// if the balance is less than 10000 BTS. uint64_t minimum_fee_percentage; /// Normally, pending dividend payments are calculated each maintenance interval in @@ -171,7 +170,7 @@ namespace graphene { namespace chain { /// /// Payouts will always occur at the next payout time whether or not it falls on a /// multiple of the distribution interval, and the timer on the distribution interval - /// are reset at payout time. So if you have the distribution interval at three days + /// are reset at payout time. So if you have the distribution interval at three days /// and the payout interval at one week, payouts will occur at days 3, 6, 7, 10, 13, 14... fc::optional minimum_distribution_interval; @@ -188,7 +187,7 @@ namespace graphene { namespace chain { */ struct asset_create_operation : public base_operation { - struct fee_parameters_type { + struct fee_parameters_type { uint64_t symbol3 = 500000 * GRAPHENE_BLOCKCHAIN_PRECISION; uint64_t symbol4 = 300000 * GRAPHENE_BLOCKCHAIN_PRECISION; uint64_t long_symbol = 5000 * GRAPHENE_BLOCKCHAIN_PRECISION; @@ -225,7 +224,7 @@ namespace graphene { namespace chain { ///Operation for creation of lottery struct lottery_asset_create_operation : public base_operation { - struct fee_parameters_type { + struct fee_parameters_type { uint64_t lottery_asset = 20 * GRAPHENE_BLOCKCHAIN_PRECISION; uint32_t price_per_kbyte = 10; /// only required for large lottery names. }; @@ -296,9 +295,9 @@ namespace graphene { namespace chain { */ struct asset_settle_operation : public base_operation { - struct fee_parameters_type { + struct fee_parameters_type { /** this fee should be high to encourage small settlement requests to - * be performed on the market rather than via forced settlement. + * be performed on the market rather than via forced settlement. * * Note that in the event of a black swan or prediction market close out * everyone will have to pay this fee. @@ -367,7 +366,7 @@ namespace graphene { namespace chain { * payments. */ uint64_t distribution_base_fee; - /** This fee is charged (in addition to the distribution_base_fee) for each + /** This fee is charged (in addition to the distribution_base_fee) for each * user the dividend payment is shared out amongst */ uint32_t distribution_fee_per_holder; @@ -429,7 +428,7 @@ namespace graphene { namespace chain { */ struct asset_update_operation : public base_operation { - struct fee_parameters_type { + struct fee_parameters_type { uint64_t fee = 500 * GRAPHENE_BLOCKCHAIN_PRECISION; uint32_t price_per_kbyte = 10; }; @@ -482,9 +481,9 @@ namespace graphene { namespace chain { * @brief Update options specific to dividend-paying assets * @ingroup operations * - * Dividend-paying assets have some options which are not relevant to other asset types. + * Dividend-paying assets have some options which are not relevant to other asset types. * This operation is used to update those options an an existing dividend-paying asset. - * This can also be used to convert a non-dividend-paying asset into a dividend-paying + * This can also be used to convert a non-dividend-paying asset into a dividend-paying * asset. * * @pre @ref issuer MUST be an existing account and MUST match asset_object::issuer on @ref asset_to_update @@ -573,8 +572,8 @@ namespace graphene { namespace chain { */ struct asset_issue_operation : public base_operation { - struct fee_parameters_type { - uint64_t fee = 20 * GRAPHENE_BLOCKCHAIN_PRECISION; + struct fee_parameters_type { + uint64_t fee = 20 * GRAPHENE_BLOCKCHAIN_PRECISION; uint32_t price_per_kbyte = GRAPHENE_BLOCKCHAIN_PRECISION; }; @@ -629,32 +628,32 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return issuer; } void validate()const; }; - + struct sweeps_vesting_claim_operation : public base_operation { struct fee_parameters_type { uint64_t fee = 20 * GRAPHENE_BLOCKCHAIN_PRECISION; }; - + asset fee; account_id_type account; asset amount_to_claim; extensions_type extensions; - - + + account_id_type fee_payer()const { return account; } void validate()const {}; }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::sweeps_vesting_claim_operation, (fee)(account)(amount_to_claim)(extensions) ) -FC_REFLECT( graphene::chain::sweeps_vesting_claim_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::sweeps_vesting_claim_operation, (fee)(account)(amount_to_claim)(extensions) ) +FC_REFLECT( graphene::protocol::sweeps_vesting_claim_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_claim_fees_operation, (fee)(issuer)(amount_to_claim)(extensions) ) -FC_REFLECT( graphene::chain::asset_claim_fees_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_claim_fees_operation, (fee)(issuer)(amount_to_claim)(extensions) ) +FC_REFLECT( graphene::protocol::asset_claim_fees_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_options, +FC_REFLECT( graphene::protocol::asset_options, (max_supply) (market_fee_percent) (max_market_fee) @@ -669,7 +668,7 @@ FC_REFLECT( graphene::chain::asset_options, (extensions) ) -FC_REFLECT( graphene::chain::dividend_asset_options, +FC_REFLECT( graphene::protocol::dividend_asset_options, (next_payout_time) (payout_interval) (minimum_fee_percentage) @@ -677,7 +676,7 @@ FC_REFLECT( graphene::chain::dividend_asset_options, (extensions) ) -FC_REFLECT( graphene::chain::bitasset_options, +FC_REFLECT( graphene::protocol::bitasset_options, (feed_lifetime_sec) (minimum_feeds) (force_settlement_delay_sec) @@ -687,27 +686,27 @@ FC_REFLECT( graphene::chain::bitasset_options, (extensions) ) -FC_REFLECT( graphene::chain::benefactor, (id)(share) ) +FC_REFLECT( graphene::protocol::benefactor, (id)(share) ) -FC_REFLECT( graphene::chain::lottery_asset_options, (benefactors)(owner)(winning_tickets)(ticket_price)(end_date)(ending_on_soldout)(is_active) ) +FC_REFLECT( graphene::protocol::lottery_asset_options, (benefactors)(owner)(winning_tickets)(ticket_price)(end_date)(ending_on_soldout)(is_active) ) -FC_REFLECT( graphene::chain::asset_create_operation::fee_parameters_type, (symbol3)(symbol4)(long_symbol)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::lottery_asset_create_operation::fee_parameters_type, (lottery_asset)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::asset_global_settle_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_settle_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_settle_cancel_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::asset_fund_fee_pool_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_update_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::asset_update_bitasset_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_update_dividend_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_update_feed_producers_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_publish_feed_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_issue_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::asset_reserve_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::asset_dividend_distribution_operation::fee_parameters_type, (distribution_base_fee)(distribution_fee_per_holder)) +FC_REFLECT( graphene::protocol::asset_create_operation::fee_parameters_type, (symbol3)(symbol4)(long_symbol)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::lottery_asset_create_operation::fee_parameters_type, (lottery_asset)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::asset_global_settle_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_settle_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_settle_cancel_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::asset_fund_fee_pool_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_update_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::asset_update_bitasset_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_update_dividend_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_update_feed_producers_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_publish_feed_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_issue_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::asset_reserve_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::asset_dividend_distribution_operation::fee_parameters_type, (distribution_base_fee)(distribution_fee_per_holder)) -FC_REFLECT( graphene::chain::asset_create_operation, +FC_REFLECT( graphene::protocol::asset_create_operation, (fee) (issuer) (symbol) @@ -717,7 +716,7 @@ FC_REFLECT( graphene::chain::asset_create_operation, (is_prediction_market) (extensions) ) -FC_REFLECT( graphene::chain::lottery_asset_create_operation, +FC_REFLECT( graphene::protocol::lottery_asset_create_operation, (fee) (issuer) (symbol) @@ -727,7 +726,7 @@ FC_REFLECT( graphene::chain::lottery_asset_create_operation, (is_prediction_market) (extensions) ) -FC_REFLECT( graphene::chain::asset_update_operation, +FC_REFLECT( graphene::protocol::asset_update_operation, (fee) (issuer) (asset_to_update) @@ -735,59 +734,60 @@ FC_REFLECT( graphene::chain::asset_update_operation, (new_options) (extensions) ) -FC_REFLECT( graphene::chain::asset_update_bitasset_operation, +FC_REFLECT( graphene::protocol::asset_update_bitasset_operation, (fee) (issuer) (asset_to_update) (new_options) (extensions) ) -FC_REFLECT( graphene::chain::asset_update_dividend_operation, +FC_REFLECT( graphene::protocol::asset_update_dividend_operation, (fee) (issuer) (asset_to_update) (new_options) (extensions) ) -FC_REFLECT( graphene::chain::asset_update_feed_producers_operation, +FC_REFLECT( graphene::protocol::asset_update_feed_producers_operation, (fee)(issuer)(asset_to_update)(new_feed_producers)(extensions) ) -FC_REFLECT( graphene::chain::asset_publish_feed_operation, +FC_REFLECT( graphene::protocol::asset_publish_feed_operation, (fee)(publisher)(asset_id)(feed)(extensions) ) -FC_REFLECT( graphene::chain::asset_settle_operation, (fee)(account)(amount)(extensions) ) -FC_REFLECT( graphene::chain::asset_settle_cancel_operation, (fee)(settlement)(account)(amount)(extensions) ) -FC_REFLECT( graphene::chain::asset_global_settle_operation, (fee)(issuer)(asset_to_settle)(settle_price)(extensions) ) -FC_REFLECT( graphene::chain::asset_issue_operation, +FC_REFLECT( graphene::protocol::asset_settle_operation, (fee)(account)(amount)(extensions) ) +FC_REFLECT( graphene::protocol::asset_settle_cancel_operation, (fee)(settlement)(account)(amount)(extensions) ) +FC_REFLECT( graphene::protocol::asset_global_settle_operation, (fee)(issuer)(asset_to_settle)(settle_price)(extensions) ) +FC_REFLECT( graphene::protocol::asset_issue_operation, (fee)(issuer)(asset_to_issue)(issue_to_account)(memo)(extensions) ) -FC_REFLECT( graphene::chain::asset_reserve_operation, +FC_REFLECT( graphene::protocol::asset_reserve_operation, (fee)(payer)(amount_to_reserve)(extensions) ) -FC_REFLECT( graphene::chain::asset_fund_fee_pool_operation, (fee)(from_account)(asset_id)(amount)(extensions) ); -FC_REFLECT( graphene::chain::asset_dividend_distribution_operation, (fee)(dividend_asset_id)(account_id)(amounts)(extensions) ); +FC_REFLECT( graphene::protocol::asset_fund_fee_pool_operation, (fee)(from_account)(asset_id)(amount)(extensions) ); +FC_REFLECT( graphene::protocol::asset_dividend_distribution_operation, (fee)(dividend_asset_id)(account_id)(amounts)(extensions) ); + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_options ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::bitasset_options ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_global_settle_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_settle_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_fund_fee_pool_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_dividend_distribution_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_claim_fees_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_update_bitasset_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_update_feed_producers_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_publish_feed_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_issue_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_reserve_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_global_settle_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_settle_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_settle_cancel_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_fund_fee_pool_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_claim_fees_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_update_bitasset_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_update_feed_producers_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_publish_feed_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_issue_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::asset_reserve_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_options ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::bitasset_options ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_global_settle_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_settle_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_fund_fee_pool_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_dividend_distribution_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_claim_fees_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_update_bitasset_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_update_feed_producers_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_publish_feed_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_issue_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_reserve_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_global_settle_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_settle_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_settle_cancel_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_fund_fee_pool_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_claim_fees_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_update_bitasset_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_update_feed_producers_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_publish_feed_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_issue_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::asset_reserve_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/authority.hpp b/libraries/protocol/include/graphene/protocol/authority.hpp similarity index 89% rename from libraries/chain/include/graphene/chain/protocol/authority.hpp rename to libraries/protocol/include/graphene/protocol/authority.hpp index d279402d..c61dc737 100644 --- a/libraries/chain/include/graphene/chain/protocol/authority.hpp +++ b/libraries/protocol/include/graphene/protocol/authority.hpp @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @class authority @@ -130,10 +130,10 @@ void add_authority_accounts( const authority& a ); -} } // namespace graphene::chain +} } // namespace graphene::protocol -FC_REFLECT( graphene::chain::authority, (weight_threshold)(account_auths)(key_auths)(address_auths) ) -// FC_REFLECT_TYPENAME( graphene::chain::authority::classification ) -FC_REFLECT_ENUM( graphene::chain::authority::classification, (owner)(active)(key) ) +FC_REFLECT( graphene::protocol::authority, (weight_threshold)(account_auths)(key_auths)(address_auths) ) +FC_REFLECT_ENUM( graphene::protocol::authority::classification, (owner)(active)(key) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::authority ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::authority ) diff --git a/libraries/chain/include/graphene/chain/protocol/balance.hpp b/libraries/protocol/include/graphene/protocol/balance.hpp similarity index 82% rename from libraries/chain/include/graphene/chain/protocol/balance.hpp rename to libraries/protocol/include/graphene/protocol/balance.hpp index 9d0b252f..c2072e56 100644 --- a/libraries/chain/include/graphene/chain/protocol/balance.hpp +++ b/libraries/protocol/include/graphene/protocol/balance.hpp @@ -22,14 +22,14 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include +#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** - * @brief Claim a balance in a @ref balanc_object + * @brief Claim a balance in a @ref balance_object * * This operation is used to claim the balance in a given @ref balance_object. If the balance object contains a * vesting balance, @ref total_claimed must not exceed @ref balance_object::available at the time of evaluation. If @@ -54,10 +54,11 @@ namespace graphene { namespace chain { } }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::balance_claim_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::balance_claim_operation, +FC_REFLECT( graphene::protocol::balance_claim_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::balance_claim_operation, (fee)(deposit_to_account)(balance_to_claim)(balance_owner_key)(total_claimed) ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::balance_claim_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::balance_claim_operation ) + diff --git a/libraries/chain/include/graphene/chain/protocol/base.hpp b/libraries/protocol/include/graphene/protocol/base.hpp similarity index 92% rename from libraries/chain/include/graphene/chain/protocol/base.hpp rename to libraries/protocol/include/graphene/protocol/base.hpp index 23c285d3..3201fd57 100644 --- a/libraries/chain/include/graphene/chain/protocol/base.hpp +++ b/libraries/protocol/include/graphene/protocol/base.hpp @@ -23,14 +23,13 @@ */ #pragma once -#include -#include -#include +#include +#include +#include #include -namespace graphene { namespace chain { - +namespace graphene { namespace protocol { struct asset; struct authority; @@ -118,12 +117,12 @@ namespace graphene { namespace chain { * @note static_variant compares only the type tag and not the * content. */ - typedef flat_set extensions_type; + typedef future_extensions::flat_set_type extensions_type; ///@} -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT_TYPENAME( graphene::chain::operation_result ) -FC_REFLECT_TYPENAME( graphene::chain::future_extensions ) -FC_REFLECT( graphene::chain::void_result, ) +FC_REFLECT_TYPENAME( graphene::protocol::operation_result ) +FC_REFLECT_TYPENAME( graphene::protocol::future_extensions ) +FC_REFLECT( graphene::protocol::void_result, ) diff --git a/libraries/chain/include/graphene/chain/protocol/betting_market.hpp b/libraries/protocol/include/graphene/protocol/betting_market.hpp similarity index 83% rename from libraries/chain/include/graphene/chain/protocol/betting_market.hpp rename to libraries/protocol/include/graphene/protocol/betting_market.hpp index 8ed9e2ac..52d40590 100644 --- a/libraries/chain/include/graphene/chain/protocol/betting_market.hpp +++ b/libraries/protocol/include/graphene/protocol/betting_market.hpp @@ -23,10 +23,10 @@ */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct betting_market_rules_create_operation : public base_operation { @@ -417,22 +417,22 @@ struct bet_adjusted_operation : public base_operation } } -FC_REFLECT( graphene::chain::betting_market_rules_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::betting_market_rules_create_operation, +FC_REFLECT( graphene::protocol::betting_market_rules_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::betting_market_rules_create_operation, (fee)(name)(description)(extensions) ) -FC_REFLECT( graphene::chain::betting_market_rules_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::betting_market_rules_update_operation, +FC_REFLECT( graphene::protocol::betting_market_rules_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::betting_market_rules_update_operation, (fee)(new_name)(new_description)(extensions)(betting_market_rules_id) ) -FC_REFLECT_ENUM( graphene::chain::betting_market_status, +FC_REFLECT_ENUM( graphene::protocol::betting_market_status, (unresolved) (frozen) (graded) (canceled) (settled) (BETTING_MARKET_STATUS_COUNT) ) -FC_REFLECT_ENUM( graphene::chain::betting_market_group_status, +FC_REFLECT_ENUM( graphene::protocol::betting_market_group_status, (upcoming) (in_play) (closed) @@ -443,51 +443,52 @@ FC_REFLECT_ENUM( graphene::chain::betting_market_group_status, (canceled) (BETTING_MARKET_GROUP_STATUS_COUNT) ) -FC_REFLECT( graphene::chain::betting_market_group_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::betting_market_group_create_operation, +FC_REFLECT( graphene::protocol::betting_market_group_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::betting_market_group_create_operation, (fee)(description)(event_id)(rules_id)(asset_id) (never_in_play)(delay_before_settling) (extensions) ) -FC_REFLECT( graphene::chain::betting_market_group_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::betting_market_group_update_operation, +FC_REFLECT( graphene::protocol::betting_market_group_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::betting_market_group_update_operation, (fee)(betting_market_group_id)(new_description)(new_rules_id)(status)(extensions) ) -FC_REFLECT( graphene::chain::betting_market_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::betting_market_create_operation, +FC_REFLECT( graphene::protocol::betting_market_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::betting_market_create_operation, (fee)(group_id)(description)(payout_condition)(extensions) ) -FC_REFLECT( graphene::chain::betting_market_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::betting_market_update_operation, +FC_REFLECT( graphene::protocol::betting_market_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::betting_market_update_operation, (fee)(betting_market_id)(new_group_id)(new_description)(new_payout_condition)(extensions) ) -FC_REFLECT_ENUM( graphene::chain::betting_market_resolution_type, (win)(not_win)(cancel)(BETTING_MARKET_RESOLUTION_COUNT) ) +FC_REFLECT_ENUM( graphene::protocol::betting_market_resolution_type, (win)(not_win)(cancel)(BETTING_MARKET_RESOLUTION_COUNT) ) -FC_REFLECT( graphene::chain::betting_market_group_resolve_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::betting_market_group_resolve_operation, +FC_REFLECT( graphene::protocol::betting_market_group_resolve_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::betting_market_group_resolve_operation, (fee)(betting_market_group_id)(resolutions)(extensions) ) -FC_REFLECT( graphene::chain::betting_market_group_resolved_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::betting_market_group_resolved_operation, +FC_REFLECT( graphene::protocol::betting_market_group_resolved_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::betting_market_group_resolved_operation, (bettor_id)(betting_market_group_id)(resolutions)(winnings)(fees_paid)(fee) ) -FC_REFLECT( graphene::chain::betting_market_group_cancel_unmatched_bets_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::betting_market_group_cancel_unmatched_bets_operation, +FC_REFLECT( graphene::protocol::betting_market_group_cancel_unmatched_bets_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::betting_market_group_cancel_unmatched_bets_operation, (fee)(betting_market_group_id)(extensions) ) -FC_REFLECT_ENUM( graphene::chain::bet_type, (back)(lay) ) -FC_REFLECT( graphene::chain::bet_place_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::bet_place_operation, +FC_REFLECT_ENUM( graphene::protocol::bet_type, (back)(lay) ) +FC_REFLECT( graphene::protocol::bet_place_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::bet_place_operation, (fee)(bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(back_or_lay)(extensions) ) -FC_REFLECT( graphene::chain::bet_matched_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::bet_matched_operation, (fee)(bettor_id)(bet_id)(amount_bet)(backer_multiplier)(guaranteed_winnings_returned) ) +FC_REFLECT( graphene::protocol::bet_matched_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::bet_matched_operation, (fee)(bettor_id)(bet_id)(amount_bet)(backer_multiplier)(guaranteed_winnings_returned) ) -FC_REFLECT( graphene::chain::bet_cancel_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::bet_cancel_operation, (fee) (bettor_id) (bet_to_cancel) (extensions) ) +FC_REFLECT( graphene::protocol::bet_cancel_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::bet_cancel_operation, (fee) (bettor_id) (bet_to_cancel) (extensions) ) -FC_REFLECT( graphene::chain::bet_canceled_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::bet_canceled_operation, (fee)(bettor_id)(bet_id)(stake_returned) ) +FC_REFLECT( graphene::protocol::bet_canceled_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::bet_canceled_operation, (fee)(bettor_id)(bet_id)(stake_returned) ) + +FC_REFLECT( graphene::protocol::bet_adjusted_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::bet_adjusted_operation, (fee) (bettor_id)(bet_id)(stake_returned) ) -FC_REFLECT( graphene::chain::bet_adjusted_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::bet_adjusted_operation, (fee) (bettor_id)(bet_id)(stake_returned) ) diff --git a/libraries/chain/include/graphene/chain/protocol/block.hpp b/libraries/protocol/include/graphene/protocol/block.hpp similarity index 80% rename from libraries/chain/include/graphene/chain/protocol/block.hpp rename to libraries/protocol/include/graphene/protocol/block.hpp index ad5b0327..a3fc9d8e 100644 --- a/libraries/chain/include/graphene/chain/protocol/block.hpp +++ b/libraries/protocol/include/graphene/protocol/block.hpp @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct block_header { @@ -57,9 +57,9 @@ namespace graphene { namespace chain { vector transactions; }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::block_header, +FC_REFLECT( graphene::protocol::block_header, (previous) (timestamp) (witness) @@ -67,10 +67,11 @@ FC_REFLECT( graphene::chain::block_header, (previous_secret) (transaction_merkle_root) (extensions) ) -FC_REFLECT_DERIVED( graphene::chain::signed_block_header, (graphene::chain::block_header), (witness_signature) ) -FC_REFLECT_DERIVED( graphene::chain::signed_block, (graphene::chain::signed_block_header), (transactions) ) +FC_REFLECT_DERIVED( graphene::protocol::signed_block_header, (graphene::protocol::block_header), (witness_signature) ) +FC_REFLECT_DERIVED( graphene::protocol::signed_block, (graphene::protocol::signed_block_header), (transactions) ) -GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::block_header) -GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::signed_block_header) -GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::signed_block) +GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::protocol::block_header) +GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::protocol::signed_block_header) +GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::protocol::signed_block) + diff --git a/libraries/chain/include/graphene/chain/protocol/buyback.hpp b/libraries/protocol/include/graphene/protocol/buyback.hpp similarity index 85% rename from libraries/chain/include/graphene/chain/protocol/buyback.hpp rename to libraries/protocol/include/graphene/protocol/buyback.hpp index 4a51e8c7..c55d7ff4 100644 --- a/libraries/chain/include/graphene/chain/protocol/buyback.hpp +++ b/libraries/protocol/include/graphene/protocol/buyback.hpp @@ -23,9 +23,9 @@ */ #pragma once -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct buyback_account_options { @@ -49,6 +49,7 @@ struct buyback_account_options } } -FC_REFLECT( graphene::chain::buyback_account_options, (asset_to_buy)(asset_to_buy_issuer)(markets) ); +FC_REFLECT( graphene::protocol::buyback_account_options, (asset_to_buy)(asset_to_buy_issuer)(markets) ); + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::buyback_account_options ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::buyback_account_options ) diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/protocol/include/graphene/protocol/chain_parameters.hpp similarity index 96% rename from libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp rename to libraries/protocol/include/graphene/protocol/chain_parameters.hpp index 3a11e99f..d4c0d0e7 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/protocol/include/graphene/protocol/chain_parameters.hpp @@ -22,18 +22,15 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include -#include -#include -#include <../hardfork.d/GPOS.hf> +#include +#include + #include -namespace graphene { namespace chain { struct fee_schedule; } } +namespace graphene { namespace protocol { + struct fee_schedule; -namespace graphene { namespace chain { struct parameter_extension { optional< bet_multiplier_type > min_bet_multiplier; @@ -47,7 +44,7 @@ namespace graphene { namespace chain { /* gpos parameters */ optional < uint32_t > gpos_period = GPOS_PERIOD; optional < uint32_t > gpos_subperiod = GPOS_SUBPERIOD; - optional < uint32_t > gpos_period_start = HARDFORK_GPOS_TIME.sec_since_epoch(); + optional < uint32_t > gpos_period_start = GPOS_PERIOD_START.sec_since_epoch(); optional < uint32_t > gpos_vesting_lockin_period = GPOS_VESTING_LOCKIN_PERIOD; /* rbac parameters */ optional < uint16_t > rbac_max_permissions_per_account = RBAC_MAX_PERMISSIONS_PER_ACCOUNT; @@ -79,7 +76,7 @@ namespace graphene { namespace chain { chain_parameters(chain_parameters&& other); chain_parameters& operator=(const chain_parameters& other); chain_parameters& operator=(chain_parameters&& other); - /** using a smart ref breaks the circular dependency created between operations and the fee schedule */ + /** using a shared_ptr breaks the circular dependency created between operations and the fee schedule */ std::shared_ptr current_fees; ///< current schedule of fees uint8_t block_interval = GRAPHENE_DEFAULT_BLOCK_INTERVAL; ///< interval in seconds between blocks uint32_t maintenance_interval = GRAPHENE_DEFAULT_MAINTENANCE_INTERVAL; ///< interval in sections between blockchain maintenance events @@ -161,7 +158,7 @@ namespace graphene { namespace chain { return extensions.value.gpos_subperiod.valid() ? *extensions.value.gpos_subperiod : GPOS_SUBPERIOD; /// gpos_period % gpos_subperiod = 0 } inline uint32_t gpos_period_start()const { - return extensions.value.gpos_period_start.valid() ? *extensions.value.gpos_period_start : HARDFORK_GPOS_TIME.sec_since_epoch(); /// current period start date + return extensions.value.gpos_period_start.valid() ? *extensions.value.gpos_period_start : GPOS_PERIOD_START.sec_since_epoch(); /// current period start date } inline uint32_t gpos_vesting_lockin_period()const { return extensions.value.gpos_vesting_lockin_period.valid() ? *extensions.value.gpos_vesting_lockin_period : GPOS_VESTING_LOCKIN_PERIOD; /// GPOS vesting lockin period @@ -224,9 +221,9 @@ namespace graphene { namespace chain { static void safe_copy(chain_parameters& to, const chain_parameters& from); }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::parameter_extension, +FC_REFLECT( graphene::protocol::parameter_extension, (min_bet_multiplier) (max_bet_multiplier) (betting_rake_fee_percentage) @@ -259,7 +256,7 @@ FC_REFLECT( graphene::chain::parameter_extension, (hive_asset) ) -FC_REFLECT( graphene::chain::chain_parameters, +FC_REFLECT( graphene::protocol::chain_parameters, (current_fees) (block_interval) (maintenance_interval) @@ -305,4 +302,5 @@ FC_REFLECT( graphene::chain::chain_parameters, (extensions) ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::chain_parameters ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::chain_parameters ) + diff --git a/libraries/chain/include/graphene/chain/protocol/committee_member.hpp b/libraries/protocol/include/graphene/protocol/committee_member.hpp similarity index 74% rename from libraries/chain/include/graphene/chain/protocol/committee_member.hpp rename to libraries/protocol/include/graphene/protocol/committee_member.hpp index 8aaed748..2b17fb07 100644 --- a/libraries/chain/include/graphene/chain/protocol/committee_member.hpp +++ b/libraries/protocol/include/graphene/protocol/committee_member.hpp @@ -22,10 +22,11 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @brief Create a committee_member object, as a bid to hold a committee_member seat on the network. @@ -93,21 +94,22 @@ namespace graphene { namespace chain { /// TODO: committee_member_resign_operation : public base_operation -} } // graphene::chain -FC_REFLECT( graphene::chain::committee_member_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::committee_member_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::committee_member_update_global_parameters_operation::fee_parameters_type, (fee) ) +} } // graphene::protocol +FC_REFLECT( graphene::protocol::committee_member_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::committee_member_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::committee_member_update_global_parameters_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::committee_member_create_operation, +FC_REFLECT( graphene::protocol::committee_member_create_operation, (fee)(committee_member_account)(url) ) -FC_REFLECT( graphene::chain::committee_member_update_operation, +FC_REFLECT( graphene::protocol::committee_member_update_operation, (fee)(committee_member)(committee_member_account)(new_url) ) -FC_REFLECT( graphene::chain::committee_member_update_global_parameters_operation, (fee)(new_parameters) ); +FC_REFLECT( graphene::protocol::committee_member_update_global_parameters_operation, (fee)(new_parameters) ); + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::committee_member_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::committee_member_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::committee_member_update_global_parameters_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::committee_member_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::committee_member_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::committee_member_update_global_parameters_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::committee_member_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::committee_member_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::committee_member_update_global_parameters_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::committee_member_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::committee_member_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::committee_member_update_global_parameters_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/confidential.hpp b/libraries/protocol/include/graphene/protocol/confidential.hpp similarity index 86% rename from libraries/chain/include/graphene/chain/protocol/confidential.hpp rename to libraries/protocol/include/graphene/protocol/confidential.hpp index 697ef35b..92c551bd 100644 --- a/libraries/chain/include/graphene/chain/protocol/confidential.hpp +++ b/libraries/protocol/include/graphene/protocol/confidential.hpp @@ -23,9 +23,11 @@ */ #pragma once -#include +#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { using fc::ecc::blind_factor_type; @@ -258,33 +260,34 @@ struct blind_transfer_operation : public base_operation ///@} endgroup stealth -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::stealth_confirmation, +FC_REFLECT( graphene::protocol::stealth_confirmation, (one_time_key)(to)(encrypted_memo) ) -FC_REFLECT( graphene::chain::stealth_confirmation::memo_data, +FC_REFLECT( graphene::protocol::stealth_confirmation::memo_data, (from)(amount)(blinding_factor)(commitment)(check) ); -FC_REFLECT( graphene::chain::blind_memo, +FC_REFLECT( graphene::protocol::blind_memo, (from)(amount)(message)(check) ) -FC_REFLECT( graphene::chain::blind_input, +FC_REFLECT( graphene::protocol::blind_input, (commitment)(owner) ) -FC_REFLECT( graphene::chain::blind_output, +FC_REFLECT( graphene::protocol::blind_output, (commitment)(range_proof)(owner)(stealth_memo) ) -FC_REFLECT( graphene::chain::transfer_to_blind_operation, +FC_REFLECT( graphene::protocol::transfer_to_blind_operation, (fee)(amount)(from)(blinding_factor)(outputs) ) -FC_REFLECT( graphene::chain::transfer_from_blind_operation, +FC_REFLECT( graphene::protocol::transfer_from_blind_operation, (fee)(amount)(to)(blinding_factor)(inputs) ) -FC_REFLECT( graphene::chain::blind_transfer_operation, +FC_REFLECT( graphene::protocol::blind_transfer_operation, (fee)(inputs)(outputs) ) -FC_REFLECT( graphene::chain::transfer_to_blind_operation::fee_parameters_type, (fee)(price_per_output) ) -FC_REFLECT( graphene::chain::transfer_from_blind_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::blind_transfer_operation::fee_parameters_type, (fee)(price_per_output) ) +FC_REFLECT( graphene::protocol::transfer_to_blind_operation::fee_parameters_type, (fee)(price_per_output) ) +FC_REFLECT( graphene::protocol::transfer_from_blind_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::blind_transfer_operation::fee_parameters_type, (fee)(price_per_output) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::transfer_to_blind_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::transfer_from_blind_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::blind_transfer_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::transfer_to_blind_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::transfer_from_blind_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::blind_transfer_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transfer_to_blind_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transfer_from_blind_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::blind_transfer_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transfer_to_blind_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transfer_from_blind_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::blind_transfer_operation ) diff --git a/libraries/protocol/include/graphene/protocol/config.hpp b/libraries/protocol/include/graphene/protocol/config.hpp new file mode 100644 index 00000000..5c89127f --- /dev/null +++ b/libraries/protocol/include/graphene/protocol/config.hpp @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#ifdef BUILD_PEERPLAYS_TESTNET +#define GRAPHENE_SYMBOL "TEST" +#define GRAPHENE_ADDRESS_PREFIX "TEST" +#else +#define GRAPHENE_SYMBOL "PPY" +#define GRAPHENE_ADDRESS_PREFIX "PPY" +#endif + + +#define GRAPHENE_MIN_ACCOUNT_NAME_LENGTH 1 +#define GRAPHENE_MAX_ACCOUNT_NAME_LENGTH 63 + +#define GRAPHENE_MIN_ASSET_SYMBOL_LENGTH 3 +#define GRAPHENE_MAX_ASSET_SYMBOL_LENGTH 16 + +#define GRAPHENE_MAX_SHARE_SUPPLY int64_t(1000000000000000ll) +#define GRAPHENE_MAX_PAY_RATE 10000 /* 100% */ +#define GRAPHENE_MAX_SIG_CHECK_DEPTH 2 +/** + * Don't allow the committee_members to publish a limit that would + * make the network unable to operate. + */ +#define GRAPHENE_MIN_TRANSACTION_SIZE_LIMIT 1024 +#define GRAPHENE_MIN_BLOCK_INTERVAL 1 /* seconds */ +#define GRAPHENE_MAX_BLOCK_INTERVAL 30 /* seconds */ + +#define GRAPHENE_DEFAULT_BLOCK_INTERVAL 3 /* seconds */ +#define GRAPHENE_DEFAULT_MAX_TRANSACTION_SIZE 2048 +#define GRAPHENE_MAX_NESTED_OBJECTS (200) +#define GRAPHENE_DEFAULT_MAX_BLOCK_SIZE (GRAPHENE_DEFAULT_MAX_TRANSACTION_SIZE*GRAPHENE_DEFAULT_BLOCK_INTERVAL*200000) +#define GRAPHENE_DEFAULT_MAX_TIME_UNTIL_EXPIRATION (60*60*24) // seconds, aka: 1 day +#define GRAPHENE_DEFAULT_MAINTENANCE_INTERVAL (60*60*24) // seconds, aka: 1 day +#define GRAPHENE_DEFAULT_MAINTENANCE_SKIP_SLOTS 3 // number of slots to skip for maintenance interval + +#define GRAPHENE_MIN_BLOCK_SIZE_LIMIT (GRAPHENE_MIN_TRANSACTION_SIZE_LIMIT*5) // 5 transactions per block +#define GRAPHENE_MIN_TRANSACTION_EXPIRATION_LIMIT (GRAPHENE_MAX_BLOCK_INTERVAL * 5) // 5 transactions per block +#define GRAPHENE_BLOCKCHAIN_PRECISION uint64_t( 100000 ) + +#define GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS 5 +#define GRAPHENE_DEFAULT_TRANSFER_FEE (1*GRAPHENE_BLOCKCHAIN_PRECISION) +#define GRAPHENE_MAX_INSTANCE_ID (uint64_t(-1)>>16) +/** percentage fields are fixed point with a denominator of 10,000 */ +#define GRAPHENE_100_PERCENT 10000 +#define GRAPHENE_1_PERCENT (GRAPHENE_100_PERCENT/100) +/** NOTE: making this a power of 2 (say 2^15) would greatly accelerate fee calcs */ +#define GRAPHENE_MAX_MARKET_FEE_PERCENT GRAPHENE_100_PERCENT +#define GRAPHENE_DEFAULT_FORCE_SETTLEMENT_DELAY (60*60*24) ///< 1 day +#define GRAPHENE_DEFAULT_FORCE_SETTLEMENT_OFFSET 0 ///< 1% +#define GRAPHENE_DEFAULT_FORCE_SETTLEMENT_MAX_VOLUME (20* GRAPHENE_1_PERCENT) ///< 20% +#define GRAPHENE_DEFAULT_PRICE_FEED_LIFETIME (60*60*24) ///< 1 day +#define GRAPHENE_MAX_FEED_PRODUCERS 200 +#define GRAPHENE_DEFAULT_MAX_AUTHORITY_MEMBERSHIP 10 +#define GRAPHENE_DEFAULT_MAX_ASSET_WHITELIST_AUTHORITIES 10 +#define GRAPHENE_DEFAULT_MAX_ASSET_FEED_PUBLISHERS 10 + +/** + * These ratios are fixed point numbers with a denominator of GRAPHENE_COLLATERAL_RATIO_DENOM, the + * minimum maitenance collateral is therefore 1.001x and the default + * maintenance ratio is 1.75x + */ +///@{ +#define GRAPHENE_COLLATERAL_RATIO_DENOM 1000 +#define GRAPHENE_MIN_COLLATERAL_RATIO 1001 ///< lower than this could result in divide by 0 +#define GRAPHENE_MAX_COLLATERAL_RATIO 32000 ///< higher than this is unnecessary and may exceed int16 storage +#define GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO 1750 ///< Call when collateral only pays off 175% the debt +#define GRAPHENE_DEFAULT_MAX_SHORT_SQUEEZE_RATIO 1500 ///< Stop calling when collateral only pays off 150% of the debt +///@} +#define GRAPHENE_DEFAULT_MARGIN_PERIOD_SEC (30*60*60*24) + +#define GRAPHENE_DEFAULT_MIN_WITNESS_COUNT (11) +#define GRAPHENE_DEFAULT_MIN_COMMITTEE_MEMBER_COUNT (11) +#define GRAPHENE_DEFAULT_MAX_WITNESSES (1001) // SHOULD BE ODD +#define GRAPHENE_DEFAULT_MAX_COMMITTEE (1001) // SHOULD BE ODD +#define GRAPHENE_DEFAULT_MAX_PROPOSAL_LIFETIME_SEC (60*60*24*7*4) // Four weeks +#define GRAPHENE_DEFAULT_COMMITTEE_PROPOSAL_REVIEW_PERIOD_SEC (60*60*24*7*2) // Two weeks +#define GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE (20*GRAPHENE_1_PERCENT) +#define GRAPHENE_DEFAULT_LIFETIME_REFERRER_PERCENT_OF_FEE (30*GRAPHENE_1_PERCENT) +#define GRAPHENE_DEFAULT_MAX_BULK_DISCOUNT_PERCENT (50*GRAPHENE_1_PERCENT) +#define GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MIN ( GRAPHENE_BLOCKCHAIN_PRECISION*int64_t(1000) ) +#define GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MAX ( GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MIN*int64_t(100) ) +#define GRAPHENE_DEFAULT_CASHBACK_VESTING_PERIOD_SEC (60*60*24*365) ///< 1 year +#define GRAPHENE_DEFAULT_CASHBACK_VESTING_THRESHOLD (GRAPHENE_BLOCKCHAIN_PRECISION*int64_t(100)) +#define GRAPHENE_DEFAULT_BURN_PERCENT_OF_FEE (20*GRAPHENE_1_PERCENT) +#define GRAPHENE_WITNESS_PAY_PERCENT_PRECISION (1000000000) +#define GRAPHENE_DEFAULT_MAX_ASSERT_OPCODE 1 +#define GRAPHENE_DEFAULT_FEE_LIQUIDATION_THRESHOLD GRAPHENE_BLOCKCHAIN_PRECISION * 100; +#define GRAPHENE_DEFAULT_ACCOUNTS_PER_FEE_SCALE 1000 +#define GRAPHENE_DEFAULT_ACCOUNT_FEE_SCALE_BITSHIFTS 4 +#define GRAPHENE_DEFAULT_MAX_BUYBACK_MARKETS 4 + +#define GRAPHENE_MAX_WORKER_NAME_LENGTH 63 + +#define GRAPHENE_MAX_URL_LENGTH 127 + +#define GRAPHENE_WITNESS_SHUFFLED_ALGORITHM 0 +#define GRAPHENE_WITNESS_SCHEDULED_ALGORITHM 1 + +// counter initialization values used to derive near and far future seeds for shuffling witnesses +// we use the fractional bits of sqrt(2) in hex +#define GRAPHENE_NEAR_SCHEDULE_CTR_IV ( (uint64_t( 0x6a09 ) << 0x30) \ + | (uint64_t( 0xe667 ) << 0x20) \ + | (uint64_t( 0xf3bc ) << 0x10) \ + | (uint64_t( 0xc908 ) ) ) + +// and the fractional bits of sqrt(3) in hex +#define GRAPHENE_FAR_SCHEDULE_CTR_IV ( (uint64_t( 0xbb67 ) << 0x30) \ + | (uint64_t( 0xae85 ) << 0x20) \ + | (uint64_t( 0x84ca ) << 0x10) \ + | (uint64_t( 0xa73b ) ) ) + +// counter used to determine bits of entropy +// must be less than or equal to secret_hash_type::data_length() +#define GRAPHENE_RNG_SEED_LENGTH (160 / 8) + +/** + * every second, the fraction of burned core asset which cycles is + * GRAPHENE_CORE_ASSET_CYCLE_RATE / (1 << GRAPHENE_CORE_ASSET_CYCLE_RATE_BITS) + */ +#define GRAPHENE_CORE_ASSET_CYCLE_RATE 17 +#define GRAPHENE_CORE_ASSET_CYCLE_RATE_BITS 32 + +#define GRAPHENE_DEFAULT_WITNESS_PAY_PER_BLOCK (GRAPHENE_BLOCKCHAIN_PRECISION * int64_t( 10) ) +#define GRAPHENE_DEFAULT_WITNESS_PAY_VESTING_SECONDS (60*60*24) +#define GRAPHENE_DEFAULT_WORKER_BUDGET_PER_DAY (GRAPHENE_BLOCKCHAIN_PRECISION * int64_t(500) * 1000 ) + +#define GRAPHENE_DEFAULT_MINIMUM_FEEDS 7 + +#define GRAPHENE_MAX_INTEREST_APR uint16_t( 10000 ) + +#define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT) + +/** + * Reserved Account IDs with special meaning + */ +///@{ +/// Represents the current committee members, two-week review period +#define GRAPHENE_COMMITTEE_ACCOUNT (graphene::protocol::account_id_type(0)) +/// Represents the current witnesses +#define GRAPHENE_WITNESS_ACCOUNT (graphene::protocol::account_id_type(1)) +/// Represents the current committee members +#define GRAPHENE_RELAXED_COMMITTEE_ACCOUNT (graphene::protocol::account_id_type(2)) +/// Represents the canonical account with NO authority (nobody can access funds in null account) +#define GRAPHENE_NULL_ACCOUNT (graphene::protocol::account_id_type(3)) +/// Represents the canonical account with WILDCARD authority (anybody can access funds in temp account) +#define GRAPHENE_TEMP_ACCOUNT (graphene::protocol::account_id_type(4)) +/// Represents the canonical account for specifying you will vote directly (as opposed to a proxy) +#define GRAPHENE_PROXY_TO_SELF_ACCOUNT (graphene::protocol::account_id_type(5)) +/// +#define GRAPHENE_RAKE_FEE_ACCOUNT_ID (graphene::protocol::account_id_type(6)) +/// Sentinel value used in the scheduler. +#define GRAPHENE_NULL_WITNESS (graphene::protocol::witness_id_type(0)) +///@} + +#define GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET (asset_id_type(743)) + +#define GRAPHENE_DEFAULT_RAKE_FEE_PERCENTAGE (3*GRAPHENE_1_PERCENT) + +/** + * Betting-related constants. + * + * We store bet multipliers as fixed-precision uint32_t. These values are + * the maximum power-of-ten bet we can have on a "symmetric" market: + * (decimal) 1.0001 - 10001 + * (fractional) 1:10000 - 10000:1 + */ +///@{ +/// betting odds (multipliers) are stored as fixed-precision, divide by this to get the actual multiplier +#define GRAPHENE_BETTING_ODDS_PRECISION 10000 +/// the smallest bet multiplier we will accept +#define GRAPHENE_BETTING_MIN_MULTIPLIER 10001 +/// the largest bet multiplier we will accept +#define GRAPHENE_BETTING_MAX_MULTIPLIER 100010000 +///@} +#define GRAPHENE_DEFAULT_MIN_BET_MULTIPLIER 10100 +#define GRAPHENE_DEFAULT_MAX_BET_MULTIPLIER 10000000 +#define GRAPHENE_DEFAULT_PERMITTED_BETTING_ODDS_INCREMENTS { { 20000, 100}, /* <= 2: 0.01 */ \ + { 30000, 200}, /* <= 3: 0.02 */ \ + { 40000, 500}, /* <= 4: 0.05 */ \ + { 60000, 1000}, /* <= 6: 0.10 */ \ + { 100000, 2000}, /* <= 10: 0.20 */ \ + { 200000, 5000}, /* <= 20: 0.50 */ \ + { 300000, 10000}, /* <= 30: 1.00 */ \ + { 500000, 20000}, /* <= 50: 2.00 */ \ + { 1000000, 50000}, /* <= 100: 5.00 */ \ + { 10000000, 100000} } /* <= 1000: 10.00 */ +#define GRAPHENE_DEFAULT_BETTING_PERCENT_FEE (2 * GRAPHENE_1_PERCENT) +#define GRAPHENE_DEFAULT_LIVE_BETTING_DELAY_TIME 5 // seconds +#define TOURNAMENT_MIN_ROUND_DELAY 0 +#define TOURNAMENT_MAX_ROUND_DELAY 600 +#define TOURNAMENT_MIN_TIME_PER_COMMIT_MOVE 0 +#define TOURNAMENT_MAN_TIME_PER_COMMIT_MOVE 600 +#define TOURNAMENT_MIN_TIME_PER_REVEAL_MOVE 0 +#define TOURNAMENT_MAX_TIME_PER_REVEAL_MOVE 600 +#define TOURNAMENT_DEFAULT_RAKE_FEE_PERCENTAGE (3*GRAPHENE_1_PERCENT) +#define TOURNAMENT_MINIMAL_RAKE_FEE_PERCENTAGE (1*GRAPHENE_1_PERCENT) +#define TOURNAMENT_MAXIMAL_RAKE_FEE_PERCENTAGE (20*GRAPHENE_1_PERCENT) +#define TOURNAMENT_MAXIMAL_REGISTRATION_DEADLINE (60*60*24*30) // seconds, 30 days +#define TOURNAMENT_MAX_NUMBER_OF_WINS 100 +#define TOURNAMENT_MAX_PLAYERS_NUMBER 256 +#define TOURNAMENT_MAX_WHITELIST_LENGTH 1000 +#define TOURNAMENT_MAX_START_TIME_IN_FUTURE (60*60*24*7*4) // 1 month +#define TOURNAMENT_MAX_START_DELAY (60*60*24*7) // 1 week +#define SON_VESTING_AMOUNT (50*GRAPHENE_BLOCKCHAIN_PRECISION) // 50 PPY +#define SON_VESTING_PERIOD (60*60*24*2) // 2 days +#define SON_DEREGISTER_TIME (60*60*12) // 12 Hours in seconds +#define SON_HEARTBEAT_FREQUENCY (60*3) // 3 minutes in seconds +#define SON_DOWN_TIME (60*3*2) // 2 Heartbeats in seconds +#define SON_BITCOIN_MIN_TX_CONFIRMATIONS (1) +#define SON_PAY_TIME (60*60*24) // 1 day +#define SON_PAY_MAX (GRAPHENE_BLOCKCHAIN_PRECISION * int64_t(200)) +#define SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE (2*GRAPHENE_1_PERCENT) +#define SWEEPS_DEFAULT_DISTRIBUTION_ASSET (graphene::protocol::asset_id_type(0)) +#define SWEEPS_VESTING_BALANCE_MULTIPLIER 100000000 +#define SWEEPS_ACCUMULATOR_ACCOUNT (graphene::protocol::account_id_type(0)) +// // The value should be harmonized with the chain constant named HARDFORK_GPOS_TIME +#ifdef BUILD_PEERPLAYS_TESTNET +#define GPOS_PERIOD_START (fc::time_point_sec::from_iso_string("2020-01-06T01:00:00")) +#else +#define GPOS_PERIOD_START (fc::time_point_sec::from_iso_string("2020-02-17T22:00:00")) +#endif +#define GPOS_PERIOD (60*60*24*30*6) // 6 months +#define GPOS_SUBPERIOD (60*60*24*30) // 1 month +#define GPOS_VESTING_LOCKIN_PERIOD (60*60*24*30) // 1 month + +#define RBAC_MIN_PERMISSION_NAME_LENGTH 3 +#define RBAC_MAX_PERMISSION_NAME_LENGTH 10 +#define RBAC_MAX_PERMISSIONS_PER_ACCOUNT 5 // 5 per account +#define RBAC_MAX_ACCOUNT_AUTHORITY_LIFETIME 180*24*60*60 // 6 months +#define RBAC_MAX_AUTHS_PER_PERMISSION 15 // 15 ops linked per permission + +#define NFT_TOKEN_MIN_LENGTH 3 +#define NFT_TOKEN_MAX_LENGTH 15 +#define NFT_URI_MAX_LENGTH GRAPHENE_MAX_URL_LENGTH + +#define GRAPHENE_DEFAULT_MAX_SONS (15) + +#define ACCOUNT_ROLES_MAX_PER_ACCOUNT 20 // Max 20 roles can be created by a resource owner +#define ACCOUNT_ROLES_MAX_LIFETIME 365*24*60*60 // 1 Year + diff --git a/libraries/chain/include/graphene/chain/protocol/custom.hpp b/libraries/protocol/include/graphene/protocol/custom.hpp similarity index 80% rename from libraries/chain/include/graphene/chain/protocol/custom.hpp rename to libraries/protocol/include/graphene/protocol/custom.hpp index 6c3af926..e21f4e7c 100644 --- a/libraries/chain/include/graphene/chain/protocol/custom.hpp +++ b/libraries/protocol/include/graphene/protocol/custom.hpp @@ -23,9 +23,10 @@ */ #pragma once -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @brief provides a generic way to add higher level protocols on top of witness consensus @@ -55,10 +56,11 @@ namespace graphene { namespace chain { } }; -} } // namespace graphene::chain +} } // namespace graphene::protocol -FC_REFLECT( graphene::chain::custom_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::custom_operation, (fee)(payer)(required_auths)(id)(data) ) +FC_REFLECT( graphene::protocol::custom_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::custom_operation, (fee)(payer)(required_auths)(id)(data) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::custom_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::custom_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::custom_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::custom_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/custom_account_authority.hpp b/libraries/protocol/include/graphene/protocol/custom_account_authority.hpp similarity index 67% rename from libraries/chain/include/graphene/chain/protocol/custom_account_authority.hpp rename to libraries/protocol/include/graphene/protocol/custom_account_authority.hpp index b3fe2903..90b5bf4d 100644 --- a/libraries/chain/include/graphene/chain/protocol/custom_account_authority.hpp +++ b/libraries/protocol/include/graphene/protocol/custom_account_authority.hpp @@ -1,9 +1,9 @@ #pragma once -#include +#include namespace graphene { -namespace chain +namespace protocol { struct custom_account_authority_create_operation : public base_operation @@ -63,14 +63,14 @@ struct custom_account_authority_delete_operation : public base_operation share_type calculate_fee(const fee_parameters_type &k) const { return k.fee; } }; -} // namespace chain +} // namespace protocol } // namespace graphene -FC_REFLECT(graphene::chain::custom_account_authority_create_operation::fee_parameters_type, (fee)(price_per_kbyte)) -FC_REFLECT(graphene::chain::custom_account_authority_create_operation, (fee)(permission_id)(operation_type)(valid_from)(valid_to)(owner_account)(extensions)) +FC_REFLECT(graphene::protocol::custom_account_authority_create_operation::fee_parameters_type, (fee)(price_per_kbyte)) +FC_REFLECT(graphene::protocol::custom_account_authority_create_operation, (fee)(permission_id)(operation_type)(valid_from)(valid_to)(owner_account)(extensions)) -FC_REFLECT(graphene::chain::custom_account_authority_update_operation::fee_parameters_type, (fee)) -FC_REFLECT(graphene::chain::custom_account_authority_update_operation, (fee)(auth_id)(new_valid_from)(new_valid_to)(owner_account)(extensions)) +FC_REFLECT(graphene::protocol::custom_account_authority_update_operation::fee_parameters_type, (fee)) +FC_REFLECT(graphene::protocol::custom_account_authority_update_operation, (fee)(auth_id)(new_valid_from)(new_valid_to)(owner_account)(extensions)) -FC_REFLECT(graphene::chain::custom_account_authority_delete_operation::fee_parameters_type, (fee)) -FC_REFLECT(graphene::chain::custom_account_authority_delete_operation, (fee)(auth_id)(owner_account)(extensions)) +FC_REFLECT(graphene::protocol::custom_account_authority_delete_operation::fee_parameters_type, (fee)) +FC_REFLECT(graphene::protocol::custom_account_authority_delete_operation, (fee)(auth_id)(owner_account)(extensions)) diff --git a/libraries/chain/include/graphene/chain/protocol/custom_permission.hpp b/libraries/protocol/include/graphene/protocol/custom_permission.hpp similarity index 66% rename from libraries/chain/include/graphene/chain/protocol/custom_permission.hpp rename to libraries/protocol/include/graphene/protocol/custom_permission.hpp index d61384c2..442b8bf2 100644 --- a/libraries/chain/include/graphene/chain/protocol/custom_permission.hpp +++ b/libraries/protocol/include/graphene/protocol/custom_permission.hpp @@ -1,9 +1,10 @@ #pragma once -#include +#include +#include namespace graphene { -namespace chain +namespace protocol { struct custom_permission_create_operation : public base_operation @@ -60,14 +61,14 @@ struct custom_permission_delete_operation : public base_operation share_type calculate_fee(const fee_parameters_type &k) const { return k.fee; } }; -} // namespace chain +} // namespace protocol } // namespace graphene -FC_REFLECT(graphene::chain::custom_permission_create_operation::fee_parameters_type, (fee)(price_per_kbyte)) -FC_REFLECT(graphene::chain::custom_permission_create_operation, (fee)(owner_account)(permission_name)(auth)(extensions)) +FC_REFLECT(graphene::protocol::custom_permission_create_operation::fee_parameters_type, (fee)(price_per_kbyte)) +FC_REFLECT(graphene::protocol::custom_permission_create_operation, (fee)(owner_account)(permission_name)(auth)(extensions)) -FC_REFLECT(graphene::chain::custom_permission_update_operation::fee_parameters_type, (fee)) -FC_REFLECT(graphene::chain::custom_permission_update_operation, (fee)(permission_id)(new_auth)(owner_account)(extensions)) +FC_REFLECT(graphene::protocol::custom_permission_update_operation::fee_parameters_type, (fee)) +FC_REFLECT(graphene::protocol::custom_permission_update_operation, (fee)(permission_id)(new_auth)(owner_account)(extensions)) -FC_REFLECT(graphene::chain::custom_permission_delete_operation::fee_parameters_type, (fee)) -FC_REFLECT(graphene::chain::custom_permission_delete_operation, (fee)(permission_id)(owner_account)(extensions)) +FC_REFLECT(graphene::protocol::custom_permission_delete_operation::fee_parameters_type, (fee)) +FC_REFLECT(graphene::protocol::custom_permission_delete_operation, (fee)(permission_id)(owner_account)(extensions)) diff --git a/libraries/chain/include/graphene/chain/protocol/event.hpp b/libraries/protocol/include/graphene/protocol/event.hpp similarity index 87% rename from libraries/chain/include/graphene/chain/protocol/event.hpp rename to libraries/protocol/include/graphene/protocol/event.hpp index 5934ad89..75012733 100644 --- a/libraries/chain/include/graphene/chain/protocol/event.hpp +++ b/libraries/protocol/include/graphene/protocol/event.hpp @@ -23,10 +23,10 @@ */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct event_create_operation : public base_operation { @@ -132,16 +132,16 @@ struct event_update_status_operation : public base_operation } } -FC_REFLECT( graphene::chain::event_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::event_create_operation, +FC_REFLECT( graphene::protocol::event_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::event_create_operation, (fee)(name)(season)(start_time)(event_group_id)(extensions) ) -FC_REFLECT( graphene::chain::event_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::event_update_operation, +FC_REFLECT( graphene::protocol::event_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::event_update_operation, (fee)(event_id)(new_event_group_id)(new_name)(new_season)(new_start_time)(new_status)(extensions) ) -FC_REFLECT_ENUM( graphene::chain::event_status, (upcoming)(in_progress)(frozen)(finished)(canceled)(settled)(STATUS_COUNT) ) -FC_REFLECT( graphene::chain::event_update_status_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::event_update_status_operation, +FC_REFLECT_ENUM( graphene::protocol::event_status, (upcoming)(in_progress)(frozen)(finished)(canceled)(settled)(STATUS_COUNT) ) +FC_REFLECT( graphene::protocol::event_update_status_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::event_update_status_operation, (fee)(event_id)(status)(scores)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/event_group.hpp b/libraries/protocol/include/graphene/protocol/event_group.hpp similarity index 83% rename from libraries/chain/include/graphene/chain/protocol/event_group.hpp rename to libraries/protocol/include/graphene/protocol/event_group.hpp index ad88ed35..daf8676d 100644 --- a/libraries/chain/include/graphene/chain/protocol/event_group.hpp +++ b/libraries/protocol/include/graphene/protocol/event_group.hpp @@ -23,10 +23,10 @@ */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct event_group_create_operation : public base_operation { @@ -86,14 +86,14 @@ struct event_group_delete_operation : public base_operation } } -FC_REFLECT( graphene::chain::event_group_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::event_group_create_operation, +FC_REFLECT( graphene::protocol::event_group_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::event_group_create_operation, (fee)(name)(sport_id)(extensions) ) -FC_REFLECT( graphene::chain::event_group_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::event_group_update_operation, +FC_REFLECT( graphene::protocol::event_group_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::event_group_update_operation, (fee)(new_sport_id)(new_name)(event_group_id)(extensions) ) -FC_REFLECT( graphene::chain::event_group_delete_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::event_group_delete_operation, +FC_REFLECT( graphene::protocol::event_group_delete_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::event_group_delete_operation, (fee)(event_group_id)(extensions) ) diff --git a/libraries/protocol/include/graphene/protocol/exceptions.hpp b/libraries/protocol/include/graphene/protocol/exceptions.hpp new file mode 100644 index 00000000..f83ef886 --- /dev/null +++ b/libraries/protocol/include/graphene/protocol/exceptions.hpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include + +#define GRAPHENE_ASSERT( expr, exc_type, FORMAT, ... ) \ + FC_MULTILINE_MACRO_BEGIN \ + if( !(expr) ) \ + FC_THROW_EXCEPTION( exc_type, FORMAT, __VA_ARGS__ ); \ + FC_MULTILINE_MACRO_END + +namespace graphene { namespace protocol { + + FC_DECLARE_EXCEPTION( protocol_exception, 4000000 ) + + FC_DECLARE_DERIVED_EXCEPTION( transaction_exception, protocol_exception, 4010000 ) + + FC_DECLARE_DERIVED_EXCEPTION( tx_missing_active_auth, transaction_exception, 4010001 ) + FC_DECLARE_DERIVED_EXCEPTION( tx_missing_owner_auth, transaction_exception, 4010002 ) + FC_DECLARE_DERIVED_EXCEPTION( tx_missing_other_auth, transaction_exception, 4010003 ) + FC_DECLARE_DERIVED_EXCEPTION( tx_irrelevant_sig, transaction_exception, 4010004 ) + FC_DECLARE_DERIVED_EXCEPTION( tx_duplicate_sig, transaction_exception, 4010005 ) + FC_DECLARE_DERIVED_EXCEPTION( invalid_committee_approval, transaction_exception, 4010006 ) + FC_DECLARE_DERIVED_EXCEPTION( insufficient_fee, transaction_exception, 4010007 ) + +} } // graphene::protocol diff --git a/libraries/chain/include/graphene/chain/protocol/ext.hpp b/libraries/protocol/include/graphene/protocol/ext.hpp similarity index 69% rename from libraries/chain/include/graphene/chain/protocol/ext.hpp rename to libraries/protocol/include/graphene/protocol/ext.hpp index 6c974630..7cb47cfc 100644 --- a/libraries/chain/include/graphene/chain/protocol/ext.hpp +++ b/libraries/protocol/include/graphene/protocol/ext.hpp @@ -26,8 +26,11 @@ #include #include #include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { + +using fc::unsigned_int; template< typename T > struct extension @@ -55,15 +58,19 @@ struct graphene_extension_pack_count_visitor template< typename Stream, typename T > struct graphene_extension_pack_read_visitor { - graphene_extension_pack_read_visitor( Stream& s, const T& v ) : stream(s), value(v) {} + graphene_extension_pack_read_visitor( Stream& s, const T& v, uint32_t _max_depth ) + : stream(s), value(v), max_depth(_max_depth - 1) + { + FC_ASSERT( _max_depth > 0 ); + } template void operator()( const char* name )const { if( (value.*member).valid() ) { - fc::raw::pack( stream, unsigned_int( which ) ); - fc::raw::pack( stream, *(value.*member) ); + fc::raw::pack( stream, unsigned_int( which ), max_depth ); + fc::raw::pack( stream, *(value.*member), max_depth ); } ++which; } @@ -71,27 +78,19 @@ struct graphene_extension_pack_read_visitor Stream& stream; const T& value; mutable uint32_t which = 0; + const uint32_t max_depth; }; -template< typename Stream, class T > -void operator<<( Stream& stream, const graphene::chain::extension& value ) -{ - graphene_extension_pack_count_visitor count_vtor( value.value ); - fc::reflector::visit( count_vtor ); - fc::raw::pack( stream, unsigned_int( count_vtor.count ) ); - graphene_extension_pack_read_visitor read_vtor( stream, value.value ); - fc::reflector::visit( read_vtor ); -} - - template< typename Stream, typename T > struct graphene_extension_unpack_visitor { - graphene_extension_unpack_visitor( Stream& s, T& v ) : stream(s), value(v) + graphene_extension_unpack_visitor( Stream& s, T& v, uint32_t _max_depth ) + : stream(s), value(v), max_depth(_max_depth - 1) { + FC_ASSERT( _max_depth > 0 ); unsigned_int c; - fc::raw::unpack( stream, c ); + fc::raw::unpack( stream, c, max_depth ); count_left = c.value; maybe_read_next_which(); } @@ -101,7 +100,7 @@ struct graphene_extension_unpack_visitor if( count_left > 0 ) { unsigned_int w; - fc::raw::unpack( stream, w ); + fc::raw::unpack( stream, w, max_depth ); next_which = w.value; } } @@ -112,7 +111,7 @@ struct graphene_extension_unpack_visitor if( (count_left > 0) && (which == next_which) ) { typename Member::value_type temp; - fc::raw::unpack( stream, temp ); + fc::raw::unpack( stream, temp, max_depth ); (value.*member) = temp; --count_left; maybe_read_next_which(); @@ -128,18 +127,10 @@ struct graphene_extension_unpack_visitor Stream& stream; T& value; + const uint32_t max_depth; }; -template< typename Stream, typename T > -void operator>>( Stream& s, graphene::chain::extension& value ) -{ - value = graphene::chain::extension(); - graphene_extension_unpack_visitor vtor( s, value.value ); - fc::reflector::visit( vtor ); - FC_ASSERT( vtor.count_left == 0 ); // unrecognized extension throws here -} - -} } // graphene::chain +} } // graphene::protocol namespace fc { @@ -172,9 +163,9 @@ struct graphene_extension_from_variant_visitor }; template< typename T > -void from_variant( const fc::variant& var, graphene::chain::extension& value, uint32_t max_depth ) +void from_variant( const fc::variant& var, graphene::protocol::extension& value, uint32_t max_depth ) { - value = graphene::chain::extension(); + value = graphene::protocol::extension(); if( var.is_null() ) return; if( var.is_array() ) @@ -205,11 +196,49 @@ struct graphene_extension_to_variant_visitor }; template< typename T > -void to_variant( const graphene::chain::extension& value, fc::variant& var, uint32_t max_depth ) +void to_variant( const graphene::protocol::extension& value, fc::variant& var, uint32_t max_depth ) { graphene_extension_to_variant_visitor vtor( value.value, max_depth ); fc::reflector::visit( vtor ); var = vtor.mvo; } +namespace raw { + +template< typename Stream, typename T > +void pack( Stream& stream, const graphene::protocol::extension& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) +{ + FC_ASSERT( _max_depth > 0 ); + --_max_depth; + graphene::protocol::graphene_extension_pack_count_visitor count_vtor( value.value ); + fc::reflector::visit( count_vtor ); + fc::raw::pack( stream, unsigned_int( count_vtor.count ), _max_depth ); + graphene::protocol::graphene_extension_pack_read_visitor read_vtor( stream, value.value, _max_depth ); + fc::reflector::visit( read_vtor ); +} + + +template< typename Stream, typename T > +void unpack( Stream& s, graphene::protocol::extension& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) +{ + FC_ASSERT( _max_depth > 0 ); + --_max_depth; + value = graphene::protocol::extension(); + graphene::protocol::graphene_extension_unpack_visitor vtor( s, value.value, _max_depth ); + fc::reflector::visit( vtor ); + FC_ASSERT( vtor.count_left == 0 ); // unrecognized extension throws here +} + +} // fc::raw + +template struct get_typename< graphene::protocol::extension > +{ + static const char* name() + { + static std::string n = std::string("graphene::protocol::extension<") + + fc::get_typename::name() + std::string(">"); + return n.c_str(); + } +}; + } // fc diff --git a/libraries/chain/include/graphene/chain/protocol/fba.hpp b/libraries/protocol/include/graphene/protocol/fba.hpp similarity index 78% rename from libraries/chain/include/graphene/chain/protocol/fba.hpp rename to libraries/protocol/include/graphene/protocol/fba.hpp index dc672436..60e08250 100644 --- a/libraries/chain/include/graphene/chain/protocol/fba.hpp +++ b/libraries/protocol/include/graphene/protocol/fba.hpp @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct fba_distribute_operation : public base_operation { @@ -33,7 +33,7 @@ struct fba_distribute_operation : public base_operation asset fee; // always zero account_id_type account_id; - fba_accumulator_id_type fba_id; + object_id_type fba_id; share_type amount; account_id_type fee_payer()const { return account_id; } @@ -43,8 +43,8 @@ struct fba_distribute_operation : public base_operation } } -FC_REFLECT( graphene::chain::fba_distribute_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::fba_distribute_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::fba_distribute_operation, (fee)(account_id)(fba_id)(amount) ) -FC_REFLECT( graphene::chain::fba_distribute_operation, (fee)(account_id)(fba_id)(amount) ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::fba_distribute_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::fba_distribute_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/fee_schedule.hpp b/libraries/protocol/include/graphene/protocol/fee_schedule.hpp similarity index 85% rename from libraries/chain/include/graphene/chain/protocol/fee_schedule.hpp rename to libraries/protocol/include/graphene/protocol/fee_schedule.hpp index 28a7e052..7e493b8c 100644 --- a/libraries/chain/include/graphene/chain/protocol/fee_schedule.hpp +++ b/libraries/protocol/include/graphene/protocol/fee_schedule.hpp @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { template struct transform_to_fee_parameters; template @@ -75,19 +75,16 @@ namespace graphene { namespace chain { /** * @note must be sorted by fee_parameters.which() and have no duplicates */ - flat_set parameters; + fee_parameters::flat_set_type parameters; uint32_t scale = GRAPHENE_100_PERCENT; ///< fee * scale / GRAPHENE_100_PERCENT }; typedef fee_schedule fee_schedule_type; -} } // graphene::chain +} } // graphene::protocol -namespace fc { - template<> struct get_typename> { static const char* name() { return "shared_ptr"; } }; -} +FC_REFLECT_TYPENAME( graphene::protocol::fee_parameters ) +FC_REFLECT( graphene::protocol::fee_schedule, (parameters)(scale) ) -FC_REFLECT_TYPENAME( graphene::chain::fee_parameters ) -FC_REFLECT( graphene::chain::fee_schedule, (parameters)(scale) ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::fee_schedule ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::fee_schedule ) diff --git a/libraries/chain/include/graphene/chain/protocol/lottery_ops.hpp b/libraries/protocol/include/graphene/protocol/lottery_ops.hpp similarity index 86% rename from libraries/chain/include/graphene/chain/protocol/lottery_ops.hpp rename to libraries/protocol/include/graphene/protocol/lottery_ops.hpp index 4f512bce..22e81d44 100644 --- a/libraries/chain/include/graphene/chain/protocol/lottery_ops.hpp +++ b/libraries/protocol/include/graphene/protocol/lottery_ops.hpp @@ -22,10 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @ingroup operations @@ -104,9 +103,9 @@ namespace graphene { namespace chain { share_type calculate_fee( const fee_parameters_type& k )const { return k.fee; } }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::ticket_purchase_operation, +FC_REFLECT( graphene::protocol::ticket_purchase_operation, (fee) (lottery) (buyer) @@ -114,10 +113,10 @@ FC_REFLECT( graphene::chain::ticket_purchase_operation, (amount) (extensions) ) -FC_REFLECT( graphene::chain::ticket_purchase_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::ticket_purchase_operation::fee_parameters_type, (fee) ) -FC_REFLECT_TYPENAME( graphene::chain::ticket_num ) -FC_REFLECT( graphene::chain::lottery_reward_operation, +FC_REFLECT_TYPENAME( graphene::protocol::ticket_num ) +FC_REFLECT( graphene::protocol::lottery_reward_operation, (fee) (lottery) (winner) @@ -126,13 +125,13 @@ FC_REFLECT( graphene::chain::lottery_reward_operation, (is_benefactor_reward) (winner_ticket_id) ) -FC_REFLECT( graphene::chain::lottery_reward_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::lottery_reward_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::lottery_end_operation, +FC_REFLECT( graphene::protocol::lottery_end_operation, (fee) (lottery) (participants) (extensions) ) -FC_REFLECT( graphene::chain::lottery_end_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::lottery_end_operation::fee_parameters_type, (fee) ) diff --git a/libraries/chain/include/graphene/chain/protocol/market.hpp b/libraries/protocol/include/graphene/protocol/market.hpp similarity index 79% rename from libraries/chain/include/graphene/chain/protocol/market.hpp rename to libraries/protocol/include/graphene/protocol/market.hpp index 2bff8c56..25b8938e 100644 --- a/libraries/chain/include/graphene/chain/protocol/market.hpp +++ b/libraries/protocol/include/graphene/protocol/market.hpp @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @class limit_order_create_operation @@ -73,7 +73,6 @@ namespace graphene { namespace chain { price get_price()const { return amount_to_sell / min_to_receive; } }; - /** * @ingroup operations * Used to cancel an existing limit order. Both fee_pay_account and the @@ -159,22 +158,22 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const { return 0; } }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::limit_order_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::limit_order_cancel_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::call_order_update_operation::fee_parameters_type, (fee) ) -/// THIS IS THE ONLY VIRTUAL OPERATION THUS FAR... -FC_REFLECT( graphene::chain::fill_order_operation::fee_parameters_type, ) -FC_REFLECT( graphene::chain::limit_order_create_operation,(fee)(seller)(amount_to_sell)(min_to_receive)(expiration)(fill_or_kill)(extensions)) -FC_REFLECT( graphene::chain::limit_order_cancel_operation,(fee)(fee_paying_account)(order)(extensions) ) -FC_REFLECT( graphene::chain::call_order_update_operation, (fee)(funding_account)(delta_collateral)(delta_debt)(extensions) ) -FC_REFLECT( graphene::chain::fill_order_operation, (fee)(order_id)(account_id)(pays)(receives) ) +FC_REFLECT( graphene::protocol::limit_order_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::limit_order_cancel_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::call_order_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::fill_order_operation::fee_parameters_type, ) // VIRTUAL +FC_REFLECT( graphene::protocol::limit_order_create_operation,(fee)(seller)(amount_to_sell)(min_to_receive)(expiration)(fill_or_kill)(extensions)) +FC_REFLECT( graphene::protocol::limit_order_cancel_operation,(fee)(fee_paying_account)(order)(extensions) ) +FC_REFLECT( graphene::protocol::call_order_update_operation, (fee)(funding_account)(delta_collateral)(delta_debt)(extensions) ) +FC_REFLECT( graphene::protocol::fill_order_operation, (fee)(order_id)(account_id)(pays)(receives) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::limit_order_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::limit_order_cancel_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::call_order_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::limit_order_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::limit_order_cancel_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::call_order_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::fill_order_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::limit_order_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::limit_order_cancel_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::call_order_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::limit_order_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::limit_order_cancel_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::call_order_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::fill_order_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/memo.hpp b/libraries/protocol/include/graphene/protocol/memo.hpp similarity index 89% rename from libraries/chain/include/graphene/chain/protocol/memo.hpp rename to libraries/protocol/include/graphene/protocol/memo.hpp index 6c5b69fb..6b074fc7 100644 --- a/libraries/chain/include/graphene/chain/protocol/memo.hpp +++ b/libraries/protocol/include/graphene/protocol/memo.hpp @@ -22,9 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @brief defines the keys used to derive the shared secret @@ -85,10 +85,11 @@ namespace graphene { namespace chain { static memo_message deserialize(const string& serial); }; -} } // namespace graphene::chain +} } // namespace graphene::protocol -FC_REFLECT( graphene::chain::memo_message, (checksum)(text) ) -FC_REFLECT( graphene::chain::memo_data, (from)(to)(nonce)(message) ) +FC_REFLECT( graphene::protocol::memo_message, (checksum)(text) ) +FC_REFLECT( graphene::protocol::memo_data, (from)(to)(nonce)(message) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::memo_message ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::memo_data ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::memo_message ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::memo_data ) diff --git a/libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp b/libraries/protocol/include/graphene/protocol/nft_lottery.hpp similarity index 75% rename from libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp rename to libraries/protocol/include/graphene/protocol/nft_lottery.hpp index 0c8ea855..81c6119c 100644 --- a/libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp +++ b/libraries/protocol/include/graphene/protocol/nft_lottery.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include +#include namespace graphene { - namespace chain + namespace protocol { struct nft_lottery_token_purchase_operation : public base_operation { @@ -75,12 +75,12 @@ namespace graphene share_type calculate_fee(const fee_parameters_type &k) const { return k.fee; } }; - } // namespace chain + } // namespace protocol } // namespace graphene -FC_REFLECT(graphene::chain::nft_lottery_token_purchase_operation::fee_parameters_type, (fee)) -FC_REFLECT(graphene::chain::nft_lottery_reward_operation::fee_parameters_type, (fee)) -FC_REFLECT(graphene::chain::nft_lottery_end_operation::fee_parameters_type, (fee)) -FC_REFLECT(graphene::chain::nft_lottery_token_purchase_operation, (fee)(lottery_id)(buyer)(tickets_to_buy)(amount)(extensions)) -FC_REFLECT(graphene::chain::nft_lottery_reward_operation, (fee)(lottery_id)(winner)(amount)(win_percentage)(is_benefactor_reward)(winner_ticket_id)(extensions)) -FC_REFLECT(graphene::chain::nft_lottery_end_operation, (fee)(lottery_id)(extensions)) \ No newline at end of file +FC_REFLECT(graphene::protocol::nft_lottery_token_purchase_operation::fee_parameters_type, (fee)) +FC_REFLECT(graphene::protocol::nft_lottery_reward_operation::fee_parameters_type, (fee)) +FC_REFLECT(graphene::protocol::nft_lottery_end_operation::fee_parameters_type, (fee)) +FC_REFLECT(graphene::protocol::nft_lottery_token_purchase_operation, (fee)(lottery_id)(buyer)(tickets_to_buy)(amount)(extensions)) +FC_REFLECT(graphene::protocol::nft_lottery_reward_operation, (fee)(lottery_id)(winner)(amount)(win_percentage)(is_benefactor_reward)(winner_ticket_id)(extensions)) +FC_REFLECT(graphene::protocol::nft_lottery_end_operation, (fee)(lottery_id)(extensions)) diff --git a/libraries/chain/include/graphene/chain/protocol/nft_ops.hpp b/libraries/protocol/include/graphene/protocol/nft_ops.hpp similarity index 71% rename from libraries/chain/include/graphene/chain/protocol/nft_ops.hpp rename to libraries/protocol/include/graphene/protocol/nft_ops.hpp index 1802623f..537f10f5 100644 --- a/libraries/chain/include/graphene/chain/protocol/nft_ops.hpp +++ b/libraries/protocol/include/graphene/protocol/nft_ops.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct nft_lottery_benefactor { account_id_type id; @@ -158,21 +158,22 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type &k) const; }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::nft_lottery_benefactor, (id)(share) ) -FC_REFLECT( graphene::chain::nft_lottery_options, (benefactors)(winning_tickets)(ticket_price)(end_date)(ending_on_soldout)(is_active)(delete_tickets_after_draw)(progressive_jackpots) ) +FC_REFLECT( graphene::protocol::nft_lottery_benefactor, (id)(share) ) +FC_REFLECT( graphene::protocol::nft_lottery_options, (benefactors)(winning_tickets)(ticket_price)(end_date)(ending_on_soldout)(is_active)(delete_tickets_after_draw)(progressive_jackpots) ) -FC_REFLECT( graphene::chain::nft_metadata_create_operation::fee_parameters_type, (fee) (price_per_kbyte) ) -FC_REFLECT( graphene::chain::nft_metadata_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::nft_mint_operation::fee_parameters_type, (fee) (price_per_kbyte) ) -FC_REFLECT( graphene::chain::nft_safe_transfer_from_operation::fee_parameters_type, (fee) (price_per_kbyte) ) -FC_REFLECT( graphene::chain::nft_approve_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::nft_set_approval_for_all_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::nft_metadata_create_operation::fee_parameters_type, (fee) (price_per_kbyte) ) +FC_REFLECT( graphene::protocol::nft_metadata_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::nft_mint_operation::fee_parameters_type, (fee) (price_per_kbyte) ) +FC_REFLECT( graphene::protocol::nft_safe_transfer_from_operation::fee_parameters_type, (fee) (price_per_kbyte) ) +FC_REFLECT( graphene::protocol::nft_approve_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::nft_set_approval_for_all_operation::fee_parameters_type, (fee) ) + +FC_REFLECT( graphene::protocol::nft_metadata_create_operation, (fee) (owner) (name) (symbol) (base_uri) (revenue_partner) (revenue_split) (is_transferable) (is_sellable) (account_role) (max_supply) (lottery_options) (extensions) ) +FC_REFLECT( graphene::protocol::nft_metadata_update_operation, (fee) (owner) (nft_metadata_id) (name) (symbol) (base_uri) (revenue_partner) (revenue_split) (is_transferable) (is_sellable) (account_role) (extensions) ) +FC_REFLECT( graphene::protocol::nft_mint_operation, (fee) (payer) (nft_metadata_id) (owner) (approved) (approved_operators) (token_uri) (extensions) ) +FC_REFLECT( graphene::protocol::nft_safe_transfer_from_operation, (fee) (operator_) (from) (to) (token_id) (data) (extensions) ) +FC_REFLECT( graphene::protocol::nft_approve_operation, (fee) (operator_) (approved) (token_id) (extensions) ) +FC_REFLECT( graphene::protocol::nft_set_approval_for_all_operation, (fee) (owner) (operator_) (approved) (extensions) ) -FC_REFLECT( graphene::chain::nft_metadata_create_operation, (fee) (owner) (name) (symbol) (base_uri) (revenue_partner) (revenue_split) (is_transferable) (is_sellable) (account_role) (max_supply) (lottery_options) (extensions) ) -FC_REFLECT( graphene::chain::nft_metadata_update_operation, (fee) (owner) (nft_metadata_id) (name) (symbol) (base_uri) (revenue_partner) (revenue_split) (is_transferable) (is_sellable) (account_role) (extensions) ) -FC_REFLECT( graphene::chain::nft_mint_operation, (fee) (payer) (nft_metadata_id) (owner) (approved) (approved_operators) (token_uri) (extensions) ) -FC_REFLECT( graphene::chain::nft_safe_transfer_from_operation, (fee) (operator_) (from) (to) (token_id) (data) (extensions) ) -FC_REFLECT( graphene::chain::nft_approve_operation, (fee) (operator_) (approved) (token_id) (extensions) ) -FC_REFLECT( graphene::chain::nft_set_approval_for_all_operation, (fee) (owner) (operator_) (approved) (extensions) ) diff --git a/libraries/db/include/graphene/db/object_id.hpp b/libraries/protocol/include/graphene/protocol/object_id.hpp similarity index 80% rename from libraries/db/include/graphene/db/object_id.hpp rename to libraries/protocol/include/graphene/protocol/object_id.hpp index 255ef048..b641e760 100644 --- a/libraries/db/include/graphene/db/object_id.hpp +++ b/libraries/protocol/include/graphene/protocol/object_id.hpp @@ -34,7 +34,6 @@ namespace graphene { namespace db { using fc::flat_map; using fc::variant; using fc::unsigned_int; - using fc::signed_int; struct object_id_type { @@ -93,14 +92,26 @@ namespace graphene { namespace db { class object; class object_database; - template + /// This template is used to downcast a generic object type to a specific xyz_object type. + template + struct object_downcast { using type = object; }; + // This macro specializes the above template for a specific xyz_object type +#define MAP_OBJECT_ID_TO_TYPE(OBJECT) \ + namespace graphene { namespace db { \ + template<> \ + struct object_downcast> { using type = OBJECT; }; \ + } } + template + using object_downcast_t = typename object_downcast::type; + + template struct object_id { - typedef T type; static const uint8_t space_id = SpaceID; static const uint8_t type_id = TypeID; - object_id(){} + object_id() = default; object_id( unsigned_int i ):instance(i){} explicit object_id( uint64_t i ):instance(i) { @@ -117,14 +128,18 @@ namespace graphene { namespace db { explicit operator uint64_t()const { return object_id_type( *this ).number; } template - const T& operator()(const DB& db)const { return db.get(*this); } + auto operator()(const DB& db)const -> const decltype(db.get(*this))& { return db.get(*this); } friend bool operator == ( const object_id& a, const object_id& b ) { return a.instance == b.instance; } friend bool operator != ( const object_id& a, const object_id& b ) { return a.instance != b.instance; } friend bool operator == ( const object_id_type& a, const object_id& b ) { return a == object_id_type(b); } friend bool operator != ( const object_id_type& a, const object_id& b ) { return a != object_id_type(b); } - friend bool operator == ( const object_id& b, const object_id_type& a ) { return a == object_id_type(b); } - friend bool operator != ( const object_id& b, const object_id_type& a ) { return a != object_id_type(b); } + friend bool operator == ( const object_id& a, const object_id_type& b ) { return object_id_type(a) == b; } + friend bool operator != ( const object_id& a, const object_id_type& b ) { return object_id_type(a) != b; } + friend bool operator == ( const object_id& a, const fc::unsigned_int& b ) { return a.instance == b; } + friend bool operator != ( const object_id& a, const fc::unsigned_int& b ) { return a.instance != b; } + friend bool operator == ( const fc::unsigned_int& a, const object_id& b ) { return a == b.instance; } + friend bool operator != ( const fc::unsigned_int& a, const object_id& b ) { return a != b.instance; } friend bool operator < ( const object_id& a, const object_id& b ) { return a.instance.value < b.instance.value; } friend bool operator > ( const object_id& a, const object_id& b ) { return a.instance.value > b.instance.value; } @@ -140,8 +155,8 @@ FC_REFLECT( graphene::db::object_id_type, (number) ) // REFLECT object_id manually because it has 2 template params namespace fc { -template -struct get_typename> +template +struct get_typename> { static const char* name() { return typeid(get_typename).name(); @@ -150,12 +165,11 @@ struct get_typename> } }; -template -struct reflector > +template +struct reflector > { - typedef graphene::db::object_id type; - typedef fc::true_type is_defined; - typedef fc::false_type is_enum; + typedef graphene::db::object_id type; + typedef std::true_type is_defined; enum member_count_enum { local_member_count = 1, total_member_count = 1 @@ -190,13 +204,13 @@ struct reflector > FC_ASSERT( type_id <= 0xff ); vo.number |= (space_id << 56) | (type_id << 48); } FC_CAPTURE_AND_RETHROW( (var) ) } - template - void to_variant( const graphene::db::object_id& var, fc::variant& vo, uint32_t max_depth = 1 ) + template + void to_variant( const graphene::db::object_id& var, fc::variant& vo, uint32_t max_depth = 1 ) { vo = fc::to_string(SpaceID) + "." + fc::to_string(TypeID) + "." + fc::to_string(var.instance.value); } - template - void from_variant( const fc::variant& var, graphene::db::object_id& vo, uint32_t max_depth = 1 ) + template + void from_variant( const fc::variant& var, graphene::db::object_id& vo, uint32_t max_depth = 1 ) { try { const auto& s = var.get_string(); auto first_dot = s.find('.'); diff --git a/libraries/chain/include/graphene/chain/protocol/offer.hpp b/libraries/protocol/include/graphene/protocol/offer.hpp similarity index 84% rename from libraries/chain/include/graphene/chain/protocol/offer.hpp rename to libraries/protocol/include/graphene/protocol/offer.hpp index 2bf3dfc2..d5a890fd 100644 --- a/libraries/chain/include/graphene/chain/protocol/offer.hpp +++ b/libraries/protocol/include/graphene/protocol/offer.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include +#include namespace graphene { - namespace chain + namespace protocol { /* @@ -118,26 +118,26 @@ namespace graphene share_type calculate_fee(const fee_parameters_type &k) const; }; - } // namespace chain + } // namespace protocol } // namespace graphene -FC_REFLECT(graphene::chain::offer_operation::fee_parameters_type, +FC_REFLECT(graphene::protocol::offer_operation::fee_parameters_type, (fee)(price_per_kbyte)); -FC_REFLECT(graphene::chain::offer_operation, +FC_REFLECT(graphene::protocol::offer_operation, (fee)(item_ids)(issuer)(minimum_price)(maximum_price)(buying_item)(offer_expiration_date)(memo)(extensions)); -FC_REFLECT(graphene::chain::bid_operation::fee_parameters_type, +FC_REFLECT(graphene::protocol::bid_operation::fee_parameters_type, (fee)); -FC_REFLECT(graphene::chain::bid_operation, +FC_REFLECT(graphene::protocol::bid_operation, (fee)(bidder)(bid_price)(offer_id)(extensions)); -FC_REFLECT(graphene::chain::cancel_offer_operation::fee_parameters_type, +FC_REFLECT(graphene::protocol::cancel_offer_operation::fee_parameters_type, (fee)); -FC_REFLECT(graphene::chain::cancel_offer_operation, +FC_REFLECT(graphene::protocol::cancel_offer_operation, (fee)(issuer)(offer_id)(extensions)); -FC_REFLECT_ENUM(graphene::chain::result_type, (Expired)(ExpiredNoBid)(Cancelled)); -FC_REFLECT(graphene::chain::finalize_offer_operation::fee_parameters_type, +FC_REFLECT_ENUM(graphene::protocol::result_type, (Expired)(ExpiredNoBid)(Cancelled)); +FC_REFLECT(graphene::protocol::finalize_offer_operation::fee_parameters_type, (fee)); -FC_REFLECT(graphene::chain::finalize_offer_operation, +FC_REFLECT(graphene::protocol::finalize_offer_operation, (fee)(fee_paying_account)(offer_id)(result)(extensions)); diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/protocol/include/graphene/protocol/operations.hpp similarity index 78% rename from libraries/chain/include/graphene/chain/protocol/operations.hpp rename to libraries/protocol/include/graphene/protocol/operations.hpp index 83d347ab..4f3cd429 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/protocol/include/graphene/protocol/operations.hpp @@ -22,44 +22,44 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @ingroup operations @@ -219,9 +219,10 @@ namespace graphene { namespace chain { operation op; }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT_TYPENAME( graphene::chain::operation ) -FC_REFLECT( graphene::chain::op_wrapper, (op) ) +FC_REFLECT_TYPENAME( graphene::protocol::operation ) +FC_REFLECT( graphene::protocol::op_wrapper, (op) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::op_wrapper ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::op_wrapper ) diff --git a/libraries/chain/include/graphene/chain/protocol/proposal.hpp b/libraries/protocol/include/graphene/protocol/proposal.hpp similarity index 87% rename from libraries/chain/include/graphene/chain/protocol/proposal.hpp rename to libraries/protocol/include/graphene/protocol/proposal.hpp index 141ec35f..42d9d854 100644 --- a/libraries/chain/include/graphene/chain/protocol/proposal.hpp +++ b/libraries/protocol/include/graphene/protocol/proposal.hpp @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @defgroup proposed_transactions The Graphene Transaction Proposal Protocol * @ingroup operations @@ -168,22 +168,23 @@ namespace graphene { namespace chain { }; ///@} -}} // graphene::chain +}} // graphene::protocol -FC_REFLECT( graphene::chain::proposal_create_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::proposal_update_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::proposal_delete_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::proposal_create_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::proposal_update_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::proposal_delete_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::proposal_create_operation, (fee)(fee_paying_account)(expiration_time) +FC_REFLECT( graphene::protocol::proposal_create_operation, (fee)(fee_paying_account)(expiration_time) (proposed_ops)(review_period_seconds)(extensions) ) -FC_REFLECT( graphene::chain::proposal_update_operation, (fee)(fee_paying_account)(proposal) +FC_REFLECT( graphene::protocol::proposal_update_operation, (fee)(fee_paying_account)(proposal) (active_approvals_to_add)(active_approvals_to_remove)(owner_approvals_to_add)(owner_approvals_to_remove) (key_approvals_to_add)(key_approvals_to_remove)(extensions) ) -FC_REFLECT( graphene::chain::proposal_delete_operation, (fee)(fee_paying_account)(using_owner_authority)(proposal)(extensions) ) +FC_REFLECT( graphene::protocol::proposal_delete_operation, (fee)(fee_paying_account)(using_owner_authority)(proposal)(extensions) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::proposal_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::proposal_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::proposal_delete_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::proposal_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::proposal_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::proposal_delete_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::proposal_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::proposal_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::proposal_delete_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::proposal_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::proposal_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::proposal_delete_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/protocol.hpp b/libraries/protocol/include/graphene/protocol/protocol.hpp similarity index 92% rename from libraries/chain/include/graphene/chain/protocol/protocol.hpp rename to libraries/protocol/include/graphene/protocol/protocol.hpp index faf6bdc2..3932639f 100644 --- a/libraries/chain/include/graphene/chain/protocol/protocol.hpp +++ b/libraries/protocol/include/graphene/protocol/protocol.hpp @@ -22,5 +22,5 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include diff --git a/libraries/chain/include/graphene/chain/pts_address.hpp b/libraries/protocol/include/graphene/protocol/pts_address.hpp similarity index 73% rename from libraries/chain/include/graphene/chain/pts_address.hpp rename to libraries/protocol/include/graphene/protocol/pts_address.hpp index c0bc80ff..7c596b98 100644 --- a/libraries/chain/include/graphene/chain/pts_address.hpp +++ b/libraries/protocol/include/graphene/protocol/pts_address.hpp @@ -23,14 +23,20 @@ */ #pragma once -#include +#include +#include #include #include #include +#include + +#include +#include +#include namespace fc { namespace ecc { class public_key; } } -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * Implements address stringification and validation from PTS @@ -46,42 +52,44 @@ namespace graphene { namespace chain { operator std::string()const; ///< converts to base58 + checksum - fc::array addr; ///< binary representation of address + std::array addr; ///< binary representation of address }; inline bool operator == ( const pts_address& a, const pts_address& b ) { return a.addr == b.addr; } inline bool operator != ( const pts_address& a, const pts_address& b ) { return a.addr != b.addr; } inline bool operator < ( const pts_address& a, const pts_address& b ) { return a.addr < b.addr; } -} } // namespace graphene::chain +} } // namespace graphene::protocol namespace std { template<> - struct hash + struct hash { public: - size_t operator()(const graphene::chain::pts_address &a) const + size_t operator()(const graphene::protocol::pts_address &a) const { size_t s; - memcpy( (char*)&s, &a.addr.data[sizeof(a)-sizeof(s)], sizeof(s) ); + std::memcpy( (char*)&s, a.addr.data() + a.addr.size() - sizeof(s), sizeof(s) ); return s; } }; } #include -FC_REFLECT( graphene::chain::pts_address, (addr) ) +FC_REFLECT( graphene::protocol::pts_address, (addr) ) namespace fc { - void to_variant( const graphene::chain::pts_address& var, fc::variant& vo, uint32_t max_depth = 1 ); - void from_variant( const fc::variant& var, graphene::chain::pts_address& vo, uint32_t max_depth = 1 ); + void to_variant( const graphene::protocol::pts_address& var, fc::variant& vo, uint32_t max_depth = 1 ); + void from_variant( const fc::variant& var, graphene::protocol::pts_address& vo, uint32_t max_depth = 1 ); + namespace raw { - extern template void pack( datastream& s, const graphene::chain::pts_address& tx, + extern template void pack( datastream& s, const graphene::protocol::pts_address& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - extern template void pack( datastream& s, const graphene::chain::pts_address& tx, + extern template void pack( datastream& s, const graphene::protocol::pts_address& tx, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + extern template void unpack( datastream& s, graphene::protocol::pts_address& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - extern template void unpack( datastream& s, graphene::chain::pts_address& tx, - uint32_t _max_depth=FC_PACK_MAX_DEPTH ); } } // fc::raw + diff --git a/libraries/chain/include/graphene/chain/protocol/random_number.hpp b/libraries/protocol/include/graphene/protocol/random_number.hpp similarity index 65% rename from libraries/chain/include/graphene/chain/protocol/random_number.hpp rename to libraries/protocol/include/graphene/protocol/random_number.hpp index 3dbe487f..957640db 100644 --- a/libraries/chain/include/graphene/chain/protocol/random_number.hpp +++ b/libraries/protocol/include/graphene/protocol/random_number.hpp @@ -1,6 +1,6 @@ #pragma once -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct random_number_store_operation : public base_operation { @@ -15,10 +15,10 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return account; } }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::random_number_store_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::random_number_store_operation, (fee) +FC_REFLECT( graphene::protocol::random_number_store_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::random_number_store_operation, (fee) (account) (random_number) (data) ) diff --git a/libraries/chain/include/graphene/chain/protocol/rock_paper_scissors.hpp b/libraries/protocol/include/graphene/protocol/rock_paper_scissors.hpp similarity index 79% rename from libraries/chain/include/graphene/chain/protocol/rock_paper_scissors.hpp rename to libraries/protocol/include/graphene/protocol/rock_paper_scissors.hpp index 1dff56cc..0ed1b56c 100644 --- a/libraries/chain/include/graphene/chain/protocol/rock_paper_scissors.hpp +++ b/libraries/protocol/include/graphene/protocol/rock_paper_scissors.hpp @@ -30,8 +30,9 @@ #include #include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct rock_paper_scissors_game_options { @@ -69,14 +70,17 @@ namespace graphene { namespace chain { uint64_t nonce1; uint64_t nonce2; rock_paper_scissors_gesture gesture; - fc::sha256 calculate_hash() const; + fc::sha256 calculate_hash() const { + std::vector full_throw_packed(fc::raw::pack(*this)); + return fc::sha256::hash(full_throw_packed.data(), full_throw_packed.size()); + } }; struct rock_paper_scissors_throw_commit { uint64_t nonce1; fc::sha256 throw_hash; - bool operator<(const graphene::chain::rock_paper_scissors_throw_commit& rhs) const + bool operator<(const graphene::protocol::rock_paper_scissors_throw_commit& rhs) const { return std::tie(nonce1, throw_hash) < std::tie(rhs.nonce1, rhs.throw_hash); } @@ -92,25 +96,25 @@ namespace graphene { namespace chain { } } -FC_REFLECT( graphene::chain::rock_paper_scissors_game_options, (insurance_enabled)(time_per_commit_move)(time_per_reveal_move)(number_of_gestures) ) +FC_REFLECT( graphene::protocol::rock_paper_scissors_game_options, (insurance_enabled)(time_per_commit_move)(time_per_reveal_move)(number_of_gestures) ) -// FC_REFLECT_TYPENAME( graphene::chain::rock_paper_scissors_gesture) -FC_REFLECT_ENUM( graphene::chain::rock_paper_scissors_gesture, +// FC_REFLECT_TYPENAME( graphene::protocol::rock_paper_scissors_gesture) +FC_REFLECT_ENUM( graphene::protocol::rock_paper_scissors_gesture, (rock) (paper) (scissors) (spock) (lizard)) -FC_REFLECT( graphene::chain::rock_paper_scissors_throw, +FC_REFLECT( graphene::protocol::rock_paper_scissors_throw, (nonce1) (nonce2) (gesture) ) -FC_REFLECT( graphene::chain::rock_paper_scissors_throw_commit, +FC_REFLECT( graphene::protocol::rock_paper_scissors_throw_commit, (nonce1) (throw_hash) ) -FC_REFLECT( graphene::chain::rock_paper_scissors_throw_reveal, +FC_REFLECT( graphene::protocol::rock_paper_scissors_throw_reveal, (nonce2)(gesture) ) diff --git a/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp b/libraries/protocol/include/graphene/protocol/sidechain_address.hpp similarity index 78% rename from libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp rename to libraries/protocol/include/graphene/protocol/sidechain_address.hpp index a5e12a03..fb2bda9a 100644 --- a/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp +++ b/libraries/protocol/include/graphene/protocol/sidechain_address.hpp @@ -1,9 +1,9 @@ #pragma once -#include +#include -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct sidechain_address_add_operation : public base_operation { @@ -59,22 +59,22 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const { return 0; } }; -} } // namespace graphene::chain +} } // namespace graphene::protocol -FC_REFLECT(graphene::chain::sidechain_address_add_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::sidechain_address_add_operation, (fee)(payer) +FC_REFLECT(graphene::protocol::sidechain_address_add_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::sidechain_address_add_operation, (fee)(payer) (sidechain_address_account)(sidechain) (deposit_public_key)(deposit_address)(deposit_address_data) (withdraw_public_key)(withdraw_address) ) -FC_REFLECT(graphene::chain::sidechain_address_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::sidechain_address_update_operation, (fee)(payer) +FC_REFLECT(graphene::protocol::sidechain_address_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::sidechain_address_update_operation, (fee)(payer) (sidechain_address_id) (sidechain_address_account)(sidechain) (deposit_public_key)(deposit_address)(deposit_address_data) (withdraw_public_key)(withdraw_address) ) -FC_REFLECT(graphene::chain::sidechain_address_delete_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::sidechain_address_delete_operation, (fee)(payer) +FC_REFLECT(graphene::protocol::sidechain_address_delete_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::sidechain_address_delete_operation, (fee)(payer) (sidechain_address_id) (sidechain_address_account)(sidechain) ) diff --git a/libraries/chain/include/graphene/chain/sidechain_defs.hpp b/libraries/protocol/include/graphene/protocol/sidechain_defs.hpp similarity index 73% rename from libraries/chain/include/graphene/chain/sidechain_defs.hpp rename to libraries/protocol/include/graphene/protocol/sidechain_defs.hpp index 7f986f96..0c8fc879 100644 --- a/libraries/chain/include/graphene/chain/sidechain_defs.hpp +++ b/libraries/protocol/include/graphene/protocol/sidechain_defs.hpp @@ -2,7 +2,7 @@ #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { enum class sidechain_type { unknown, @@ -15,7 +15,7 @@ enum class sidechain_type { } } -FC_REFLECT_ENUM(graphene::chain::sidechain_type, +FC_REFLECT_ENUM(graphene::protocol::sidechain_type, (unknown) (bitcoin) (ethereum) diff --git a/libraries/chain/include/graphene/chain/protocol/sidechain_transaction.hpp b/libraries/protocol/include/graphene/protocol/sidechain_transaction.hpp similarity index 67% rename from libraries/chain/include/graphene/chain/protocol/sidechain_transaction.hpp rename to libraries/protocol/include/graphene/protocol/sidechain_transaction.hpp index 01a4ce74..9564a3d9 100644 --- a/libraries/chain/include/graphene/chain/protocol/sidechain_transaction.hpp +++ b/libraries/protocol/include/graphene/protocol/sidechain_transaction.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include -#include -#include +#include +#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct sidechain_transaction_create_operation : public base_operation { @@ -64,25 +64,25 @@ namespace graphene { namespace chain { share_type calculate_fee( const fee_parameters_type& k )const { return 0; } }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::sidechain_transaction_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::sidechain_transaction_create_operation, (fee)(payer) +FC_REFLECT( graphene::protocol::sidechain_transaction_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::sidechain_transaction_create_operation, (fee)(payer) (sidechain) (object_id) (transaction) (signers) ) -FC_REFLECT( graphene::chain::sidechain_transaction_sign_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::sidechain_transaction_sign_operation, (fee)(signer)(payer) +FC_REFLECT( graphene::protocol::sidechain_transaction_sign_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::sidechain_transaction_sign_operation, (fee)(signer)(payer) (sidechain_transaction_id) (signature) ) -FC_REFLECT( graphene::chain::sidechain_transaction_send_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::sidechain_transaction_send_operation, (fee)(payer) +FC_REFLECT( graphene::protocol::sidechain_transaction_send_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::sidechain_transaction_send_operation, (fee)(payer) (sidechain_transaction_id) (sidechain_transaction) ) -FC_REFLECT( graphene::chain::sidechain_transaction_settle_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::sidechain_transaction_settle_operation, (fee)(payer) +FC_REFLECT( graphene::protocol::sidechain_transaction_settle_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::sidechain_transaction_settle_operation, (fee)(payer) (sidechain_transaction_id) ) diff --git a/libraries/chain/include/graphene/chain/protocol/son.hpp b/libraries/protocol/include/graphene/protocol/son.hpp similarity index 69% rename from libraries/chain/include/graphene/chain/protocol/son.hpp rename to libraries/protocol/include/graphene/protocol/son.hpp index 9d6ef653..b986e9d7 100644 --- a/libraries/chain/include/graphene/chain/protocol/son.hpp +++ b/libraries/protocol/include/graphene/protocol/son.hpp @@ -1,9 +1,9 @@ #pragma once -#include -#include -#include -namespace graphene { namespace chain { +#include +#include + +namespace graphene { namespace protocol { struct son_create_operation : public base_operation { @@ -96,25 +96,25 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const { return 0; } }; -} } // namespace graphene::chain +} } // namespace graphene::protocol -FC_REFLECT(graphene::chain::son_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_create_operation, (fee)(owner_account)(url)(deposit)(signing_key)(sidechain_public_keys) +FC_REFLECT(graphene::protocol::son_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_create_operation, (fee)(owner_account)(url)(deposit)(signing_key)(sidechain_public_keys) (pay_vb) ) -FC_REFLECT(graphene::chain::son_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_update_operation, (fee)(son_id)(owner_account)(new_url)(new_deposit) +FC_REFLECT(graphene::protocol::son_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_update_operation, (fee)(son_id)(owner_account)(new_url)(new_deposit) (new_signing_key)(new_sidechain_public_keys)(new_pay_vb) ) -FC_REFLECT(graphene::chain::son_deregister_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_deregister_operation, (fee)(son_id)(payer) ) +FC_REFLECT(graphene::protocol::son_deregister_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_deregister_operation, (fee)(son_id)(payer) ) -FC_REFLECT(graphene::chain::son_heartbeat_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_heartbeat_operation, (fee)(son_id)(owner_account)(ts) ) +FC_REFLECT(graphene::protocol::son_heartbeat_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_heartbeat_operation, (fee)(son_id)(owner_account)(ts) ) -FC_REFLECT(graphene::chain::son_report_down_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_report_down_operation, (fee)(son_id)(payer)(down_ts) ) +FC_REFLECT(graphene::protocol::son_report_down_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_report_down_operation, (fee)(son_id)(payer)(down_ts) ) -FC_REFLECT_ENUM( graphene::chain::son_maintenance_request_type, (request_maintenance)(cancel_request_maintenance) ) -FC_REFLECT(graphene::chain::son_maintenance_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_maintenance_operation, (fee)(son_id)(owner_account)(request_type) ) +FC_REFLECT_ENUM( graphene::protocol::son_maintenance_request_type, (request_maintenance)(cancel_request_maintenance) ) +FC_REFLECT(graphene::protocol::son_maintenance_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_maintenance_operation, (fee)(son_id)(owner_account)(request_type) ) diff --git a/libraries/chain/include/graphene/chain/son_info.hpp b/libraries/protocol/include/graphene/protocol/son_info.hpp similarity index 89% rename from libraries/chain/include/graphene/chain/son_info.hpp rename to libraries/protocol/include/graphene/protocol/son_info.hpp index 2bfecac4..5d86d520 100644 --- a/libraries/chain/include/graphene/chain/son_info.hpp +++ b/libraries/protocol/include/graphene/protocol/son_info.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { using namespace graphene::db; /** @@ -40,7 +40,7 @@ namespace graphene { namespace chain { } } -FC_REFLECT( graphene::chain::son_info, +FC_REFLECT( graphene::protocol::son_info, (son_id) (weight) (signing_key) diff --git a/libraries/chain/include/graphene/chain/protocol/son_wallet.hpp b/libraries/protocol/include/graphene/protocol/son_wallet.hpp similarity index 60% rename from libraries/chain/include/graphene/chain/protocol/son_wallet.hpp rename to libraries/protocol/include/graphene/protocol/son_wallet.hpp index 5194bed2..2be24c1a 100644 --- a/libraries/chain/include/graphene/chain/protocol/son_wallet.hpp +++ b/libraries/protocol/include/graphene/protocol/son_wallet.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct son_wallet_recreate_operation : public base_operation { @@ -32,9 +32,9 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const { return 0; } }; -} } // namespace graphene::chain +} } // namespace graphene::protocol -FC_REFLECT(graphene::chain::son_wallet_recreate_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_wallet_recreate_operation, (fee)(payer)(sons) ) -FC_REFLECT(graphene::chain::son_wallet_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_wallet_update_operation, (fee)(payer)(son_wallet_id)(sidechain)(address) ) +FC_REFLECT(graphene::protocol::son_wallet_recreate_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_wallet_recreate_operation, (fee)(payer)(sons) ) +FC_REFLECT(graphene::protocol::son_wallet_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_wallet_update_operation, (fee)(payer)(son_wallet_id)(sidechain)(address) ) diff --git a/libraries/chain/include/graphene/chain/protocol/son_wallet_deposit.hpp b/libraries/protocol/include/graphene/protocol/son_wallet_deposit.hpp similarity index 68% rename from libraries/chain/include/graphene/chain/protocol/son_wallet_deposit.hpp rename to libraries/protocol/include/graphene/protocol/son_wallet_deposit.hpp index 1b6a02c7..91100ec0 100644 --- a/libraries/chain/include/graphene/chain/protocol/son_wallet_deposit.hpp +++ b/libraries/protocol/include/graphene/protocol/son_wallet_deposit.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct son_wallet_deposit_create_operation : public base_operation { @@ -23,9 +23,9 @@ namespace graphene { namespace chain { std::string sidechain_to; std::string sidechain_currency; fc::safe sidechain_amount; - chain::account_id_type peerplays_from; - chain::account_id_type peerplays_to; - chain::asset peerplays_asset; + account_id_type peerplays_from; + account_id_type peerplays_to; + asset peerplays_asset; account_id_type fee_payer()const { return payer; } share_type calculate_fee(const fee_parameters_type& k)const { return 0; } @@ -44,14 +44,14 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const { return 0; } }; -} } // namespace graphene::chain +} } // namespace graphene::protocol -FC_REFLECT(graphene::chain::son_wallet_deposit_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_wallet_deposit_create_operation, (fee)(payer) +FC_REFLECT(graphene::protocol::son_wallet_deposit_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_wallet_deposit_create_operation, (fee)(payer) (son_id) (timestamp) (block_num) (sidechain) (sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_currency) (sidechain_amount) (peerplays_from) (peerplays_to) (peerplays_asset) ) -FC_REFLECT(graphene::chain::son_wallet_deposit_process_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_wallet_deposit_process_operation, (fee)(payer) +FC_REFLECT(graphene::protocol::son_wallet_deposit_process_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_wallet_deposit_process_operation, (fee)(payer) (son_wallet_deposit_id) ) diff --git a/libraries/chain/include/graphene/chain/protocol/son_wallet_withdraw.hpp b/libraries/protocol/include/graphene/protocol/son_wallet_withdraw.hpp similarity index 70% rename from libraries/chain/include/graphene/chain/protocol/son_wallet_withdraw.hpp rename to libraries/protocol/include/graphene/protocol/son_wallet_withdraw.hpp index 0461d4b2..8e289d5c 100644 --- a/libraries/chain/include/graphene/chain/protocol/son_wallet_withdraw.hpp +++ b/libraries/protocol/include/graphene/protocol/son_wallet_withdraw.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct son_wallet_withdraw_create_operation : public base_operation { @@ -19,8 +19,8 @@ namespace graphene { namespace chain { sidechain_type sidechain; std::string peerplays_uid; std::string peerplays_transaction_id; - chain::account_id_type peerplays_from; - chain::asset peerplays_asset; + account_id_type peerplays_from; + asset peerplays_asset; sidechain_type withdraw_sidechain; std::string withdraw_address; std::string withdraw_currency; @@ -43,14 +43,14 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const { return 0; } }; -} } // namespace graphene::chain +} } // namespace graphene::protocol -FC_REFLECT(graphene::chain::son_wallet_withdraw_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_wallet_withdraw_create_operation, (fee)(payer) +FC_REFLECT(graphene::protocol::son_wallet_withdraw_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_wallet_withdraw_create_operation, (fee)(payer) (son_id) (timestamp) (block_num) (sidechain) (peerplays_uid) (peerplays_transaction_id) (peerplays_from) (peerplays_asset) (withdraw_sidechain) (withdraw_address) (withdraw_currency) (withdraw_amount) ) -FC_REFLECT(graphene::chain::son_wallet_withdraw_process_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_wallet_withdraw_process_operation, (fee)(payer) +FC_REFLECT(graphene::protocol::son_wallet_withdraw_process_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::protocol::son_wallet_withdraw_process_operation, (fee)(payer) (son_wallet_withdraw_id) ) diff --git a/libraries/chain/include/graphene/chain/protocol/special_authority.hpp b/libraries/protocol/include/graphene/protocol/special_authority.hpp similarity index 77% rename from libraries/chain/include/graphene/chain/protocol/special_authority.hpp rename to libraries/protocol/include/graphene/protocol/special_authority.hpp index 05a80719..a780728c 100644 --- a/libraries/chain/include/graphene/chain/protocol/special_authority.hpp +++ b/libraries/protocol/include/graphene/protocol/special_authority.hpp @@ -23,10 +23,9 @@ */ #pragma once -#include -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct no_special_authority {}; @@ -43,10 +42,11 @@ typedef static_variant< void validate_special_authority( const special_authority& auth ); -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::no_special_authority, ) -FC_REFLECT( graphene::chain::top_holders_special_authority, (asset)(num_top_holders) ) -FC_REFLECT_TYPENAME( graphene::chain::special_authority ) +FC_REFLECT( graphene::protocol::no_special_authority, ) +FC_REFLECT( graphene::protocol::top_holders_special_authority, (asset)(num_top_holders) ) +FC_REFLECT_TYPENAME( graphene::protocol::special_authority ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::top_holders_special_authority ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::top_holders_special_authority ) diff --git a/libraries/chain/include/graphene/chain/protocol/sport.hpp b/libraries/protocol/include/graphene/protocol/sport.hpp similarity index 82% rename from libraries/chain/include/graphene/chain/protocol/sport.hpp rename to libraries/protocol/include/graphene/protocol/sport.hpp index a33e70e9..cdb64984 100644 --- a/libraries/chain/include/graphene/chain/protocol/sport.hpp +++ b/libraries/protocol/include/graphene/protocol/sport.hpp @@ -23,10 +23,10 @@ */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { struct sport_create_operation : public base_operation { @@ -74,14 +74,14 @@ struct sport_delete_operation : public base_operation } } -FC_REFLECT( graphene::chain::sport_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::sport_create_operation, +FC_REFLECT( graphene::protocol::sport_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::sport_create_operation, (fee)(name)(extensions) ) -FC_REFLECT( graphene::chain::sport_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::sport_update_operation, +FC_REFLECT( graphene::protocol::sport_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::sport_update_operation, (fee)(sport_id)(new_name)(extensions) ) -FC_REFLECT( graphene::chain::sport_delete_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::sport_delete_operation, +FC_REFLECT( graphene::protocol::sport_delete_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::sport_delete_operation, (fee)(sport_id)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/tournament.hpp b/libraries/protocol/include/graphene/protocol/tournament.hpp similarity index 88% rename from libraries/chain/include/graphene/chain/protocol/tournament.hpp rename to libraries/protocol/include/graphene/protocol/tournament.hpp index 5c9398d7..6eebece2 100644 --- a/libraries/chain/include/graphene/chain/protocol/tournament.hpp +++ b/libraries/protocol/include/graphene/protocol/tournament.hpp @@ -30,11 +30,10 @@ #include #include -#include -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { enum class payout_type { @@ -220,15 +219,15 @@ namespace graphene { namespace chain { } } -FC_REFLECT_ENUM(graphene::chain::payout_type, +FC_REFLECT_ENUM(graphene::protocol::payout_type, (prize_award) (buyin_refund) (rake_fee) ) -FC_REFLECT_TYPENAME( graphene::chain::game_specific_options ) -FC_REFLECT_TYPENAME( graphene::chain::game_specific_moves ) -FC_REFLECT( graphene::chain::tournament_options, +FC_REFLECT_TYPENAME( graphene::protocol::game_specific_options ) +FC_REFLECT_TYPENAME( graphene::protocol::game_specific_moves ) +FC_REFLECT( graphene::protocol::tournament_options, (registration_deadline) (number_of_players) (buy_in) @@ -239,31 +238,31 @@ FC_REFLECT( graphene::chain::tournament_options, (number_of_wins) (meta) (game_options)) -FC_REFLECT( graphene::chain::tournament_create_operation, +FC_REFLECT( graphene::protocol::tournament_create_operation, (fee) (creator) (options) (extensions)) -FC_REFLECT( graphene::chain::tournament_join_operation, +FC_REFLECT( graphene::protocol::tournament_join_operation, (fee) (payer_account_id) (player_account_id) (tournament_id) (buy_in) (extensions)) -FC_REFLECT( graphene::chain::tournament_leave_operation, +FC_REFLECT( graphene::protocol::tournament_leave_operation, (fee) (canceling_account_id) (player_account_id) (tournament_id) (extensions)) -FC_REFLECT( graphene::chain::game_move_operation, +FC_REFLECT( graphene::protocol::game_move_operation, (fee) (game_id) (player_account_id) (move) (extensions)) -FC_REFLECT( graphene::chain::tournament_payout_operation, +FC_REFLECT( graphene::protocol::tournament_payout_operation, (fee) (payout_account_id) (tournament_id) @@ -271,9 +270,9 @@ FC_REFLECT( graphene::chain::tournament_payout_operation, (type) (extensions)) -FC_REFLECT( graphene::chain::tournament_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::tournament_join_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::tournament_leave_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::game_move_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::tournament_payout_operation::fee_parameters_type, ) +FC_REFLECT( graphene::protocol::tournament_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::tournament_join_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::tournament_leave_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::game_move_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::tournament_payout_operation::fee_parameters_type, ) diff --git a/libraries/chain/include/graphene/chain/protocol/transaction.hpp b/libraries/protocol/include/graphene/protocol/transaction.hpp similarity index 93% rename from libraries/chain/include/graphene/chain/protocol/transaction.hpp rename to libraries/protocol/include/graphene/protocol/transaction.hpp index 5dbb7752..aac83c95 100644 --- a/libraries/chain/include/graphene/chain/protocol/transaction.hpp +++ b/libraries/protocol/include/graphene/protocol/transaction.hpp @@ -22,12 +22,9 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include -#include - -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @defgroup transactions Transactions @@ -234,14 +231,15 @@ namespace graphene { namespace chain { /// @} transactions group -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::transaction, (ref_block_num)(ref_block_prefix)(expiration)(operations)(extensions) ) +FC_REFLECT( graphene::protocol::transaction, (ref_block_num)(ref_block_prefix)(expiration)(operations)(extensions) ) // Note: not reflecting signees field for backward compatibility; in addition, it should not be in p2p messages -FC_REFLECT_DERIVED( graphene::chain::signed_transaction, (graphene::chain::transaction), (signatures) ) -FC_REFLECT_DERIVED( graphene::chain::processed_transaction, (graphene::chain::signed_transaction), (operation_results) ) +FC_REFLECT_DERIVED( graphene::protocol::signed_transaction, (graphene::protocol::transaction), (signatures) ) +FC_REFLECT_DERIVED( graphene::protocol::processed_transaction, (graphene::protocol::signed_transaction), + (operation_results) ) +GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::protocol::transaction) +GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::protocol::signed_transaction) +GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::protocol::processed_transaction) -GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::transaction) -GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::signed_transaction) -GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::processed_transaction) diff --git a/libraries/chain/include/graphene/chain/protocol/transfer.hpp b/libraries/protocol/include/graphene/protocol/transfer.hpp similarity index 78% rename from libraries/chain/include/graphene/chain/protocol/transfer.hpp rename to libraries/protocol/include/graphene/protocol/transfer.hpp index 5366a7ab..1a335613 100644 --- a/libraries/chain/include/graphene/chain/protocol/transfer.hpp +++ b/libraries/protocol/include/graphene/protocol/transfer.hpp @@ -22,11 +22,11 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include +#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @ingroup operations @@ -99,15 +99,16 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const; }; -}} // graphene::chain +}} // graphene::protocol -FC_REFLECT( graphene::chain::transfer_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::override_transfer_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::transfer_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::override_transfer_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::override_transfer_operation, (fee)(issuer)(from)(to)(amount)(memo)(extensions) ) -FC_REFLECT( graphene::chain::transfer_operation, (fee)(from)(to)(amount)(memo)(extensions) ) +FC_REFLECT( graphene::protocol::override_transfer_operation, (fee)(issuer)(from)(to)(amount)(memo)(extensions) ) +FC_REFLECT( graphene::protocol::transfer_operation, (fee)(from)(to)(amount)(memo)(extensions) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::transfer_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::override_transfer_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::transfer_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::override_transfer_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transfer_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::override_transfer_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::transfer_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::override_transfer_operation ) diff --git a/libraries/protocol/include/graphene/protocol/types.hpp b/libraries/protocol/include/graphene/protocol/types.hpp new file mode 100644 index 00000000..e91e014b --- /dev/null +++ b/libraries/protocol/include/graphene/protocol/types.hpp @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#define GRAPHENE_EXTERNAL_SERIALIZATION(ext, type) \ +namespace fc { \ + ext template void from_variant( const variant& v, type& vo, uint32_t max_depth ); \ + ext template void to_variant( const type& v, variant& vo, uint32_t max_depth ); \ +namespace raw { \ + ext template void pack< datastream, type >( datastream& s, const type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \ + ext template void pack< sha256::encoder, type >( sha256::encoder& s, const type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \ + ext template void pack< datastream, type >( datastream& s, const type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \ + ext template void unpack< datastream, type >( datastream& s, type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \ +} } // fc::raw + +#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; + +using std::map; +using std::vector; +using std::unordered_map; +using std::string; +using std::deque; +using std::shared_ptr; +using std::weak_ptr; +using std::unique_ptr; +using std::set; +using std::pair; +using std::enable_shared_from_this; +using std::tie; +using std::make_pair; + +using fc::variant_object; +using fc::variant; +using fc::enum_type; +using fc::optional; +using fc::unsigned_int; +using fc::time_point_sec; +using fc::time_point; +using fc::safe; +using fc::flat_map; +using fc::flat_set; +using fc::static_variant; +using fc::ecc::range_proof_type; +using fc::ecc::range_proof_info; +using fc::ecc::commitment_type; +struct void_t{}; + +using private_key_type = fc::ecc::private_key; +using chain_id_type = fc::sha256; +using ratio_type = boost::rational; + +enum asset_issuer_permission_flags { + charge_market_fee = 0x01, /**< an issuer-specified percentage of all market trades in this asset is paid to the issuer */ + white_list = 0x02, /**< accounts must be whitelisted in order to hold this asset */ + override_authority = 0x04, /**< issuer may transfer asset back to himself */ + transfer_restricted = 0x08, /**< require the issuer to be one party to every transfer */ + disable_force_settle = 0x10, /**< disable force settling */ + global_settle = 0x20, /**< allow the bitasset issuer to force a global settling -- this may be set in permissions, but not flags */ + disable_confidential = 0x40, /**< allow the asset to be used with confidential transactions */ + witness_fed_asset = 0x80, /**< allow the asset to be fed by witnesses */ + committee_fed_asset = 0x100 /**< allow the asset to be fed by the committee */ +}; +const static uint32_t ASSET_ISSUER_PERMISSION_MASK = + charge_market_fee + | white_list + | override_authority + | transfer_restricted + | disable_force_settle + | global_settle + | disable_confidential + | witness_fed_asset + | committee_fed_asset; +const static uint32_t UIA_ASSET_ISSUER_PERMISSION_MASK = + charge_market_fee + | white_list + | override_authority + | transfer_restricted + | disable_confidential; + +enum reserved_spaces { + relative_protocol_ids = 0, + protocol_ids = 1, + implementation_ids = 2 +}; + +inline bool is_relative(object_id_type o) { return o.space() == 0; } + +using block_id_type = fc::ripemd160; +using checksum_type = fc::ripemd160; +using transaction_id_type = fc::ripemd160; +using digest_type = fc::sha256; +using signature_type = fc::ecc::compact_signature; +using share_type = safe; +using weight_type = uint16_t; +using secret_hash_type = fc::ripemd160; +using bet_multiplier_type = uint32_t; +using internationalized_string_type = flat_map; + +struct public_key_type { + struct binary_key { + binary_key() = default; + uint32_t check = 0; + fc::ecc::public_key_data data; + }; + fc::ecc::public_key_data key_data; + public_key_type(); + public_key_type(const fc::ecc::public_key_data& data); + public_key_type(const fc::ecc::public_key& pubkey); + explicit public_key_type(const std::string& base58str); + operator fc::ecc::public_key_data() const; + operator fc::ecc::public_key() const; + explicit operator std::string() const; + friend bool operator == (const public_key_type& p1, const fc::ecc::public_key& p2); + friend bool operator == (const public_key_type& p1, const public_key_type& p2); + friend bool operator != (const public_key_type& p1, const public_key_type& p2); + // TODO: This is temporary for testing + bool is_valid_v1( const std::string& base58str ); + bool is_valid_muse( const std::string& base58str ); +}; + +class pubkey_comparator { +public: + inline bool operator()(const public_key_type& a, const public_key_type& b) const { + return a.key_data < b.key_data; + } +}; + +struct fee_schedule; +} } // graphene::protocol + +namespace fc { +void to_variant(const graphene::protocol::public_key_type& var, fc::variant& vo, uint32_t max_depth = 2); +void from_variant(const fc::variant& var, graphene::protocol::public_key_type& vo, uint32_t max_depth = 2); + + +template<> +struct get_typename> { static const char* name() { + return "shared_ptr"; +} }; +template<> +struct get_typename> { static const char* name() { + return "shared_ptr"; +} }; +void from_variant( const fc::variant& var, std::shared_ptr& vo, + uint32_t max_depth = 2 ); + +} // fc::raw + +GRAPHENE_DEFINE_IDS(protocol, protocol_ids, /*protocol objects are not prefixed*/, + (null) + (base) + (account) + (asset) + (force_settlement) + (committee_member) + (witness) + (limit_order) + (call_order) + (custom) + (proposal) + (operation_history) + (withdraw_permission) + (vesting_balance) + (worker) + (balance) + (tournament) + (tournament_details) + (match) + (game) + (sport) + (event_group) + (event) + (betting_market_rules) + (betting_market_group) + (betting_market) + (bet) + (custom_permission) + (custom_account_authority) + (offer) + (nft_metadata) + (nft) + (account_role) + (son) + (son_proposal) + (son_wallet) + (son_wallet_deposit) + (son_wallet_withdraw) + (sidechain_address) + (sidechain_transaction) + (random_number)) + +FC_REFLECT(graphene::protocol::public_key_type, (key_data)) +FC_REFLECT(graphene::protocol::public_key_type::binary_key, (data)(check)) + +FC_REFLECT_TYPENAME(graphene::protocol::share_type) +FC_REFLECT(graphene::protocol::void_t,) + +FC_REFLECT_ENUM(graphene::protocol::asset_issuer_permission_flags, + (charge_market_fee) + (white_list) + (transfer_restricted) + (override_authority) + (disable_force_settle) + (global_settle) + (disable_confidential) + (witness_fed_asset) + (committee_fed_asset)) + +namespace fc { namespace raw { + extern template void pack( datastream& s, const graphene::protocol::public_key_type& tx, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + extern template void pack( datastream& s, const graphene::protocol::public_key_type& tx, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + extern template void unpack( datastream& s, graphene::protocol::public_key_type& tx, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); +} } // fc::raw diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/protocol/include/graphene/protocol/vesting.hpp similarity index 76% rename from libraries/chain/include/graphene/chain/protocol/vesting.hpp rename to libraries/protocol/include/graphene/protocol/vesting.hpp index 9bde1008..35f34bf1 100644 --- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp +++ b/libraries/protocol/include/graphene/protocol/vesting.hpp @@ -22,10 +22,11 @@ * THE SOFTWARE. */ #pragma once -#include -#include -namespace graphene { namespace chain { +#include +#include + +namespace graphene { namespace protocol { enum class vesting_balance_type { normal, gpos, son }; @@ -124,22 +125,23 @@ namespace graphene { namespace chain { } }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::vesting_balance_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::vesting_balance_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::vesting_balance_withdraw_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy)(balance_type) ) -FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation, (fee)(vesting_balance)(owner)(amount) ) +FC_REFLECT( graphene::protocol::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy)(balance_type) ) +FC_REFLECT( graphene::protocol::vesting_balance_withdraw_operation, (fee)(vesting_balance)(owner)(amount) ) -FC_REFLECT(graphene::chain::linear_vesting_policy_initializer, (begin_timestamp)(vesting_cliff_seconds)(vesting_duration_seconds) ) -FC_REFLECT(graphene::chain::cdd_vesting_policy_initializer, (start_claim)(vesting_seconds) ) -FC_REFLECT(graphene::chain::dormant_vesting_policy_initializer, ) -FC_REFLECT_TYPENAME( graphene::chain::vesting_policy_initializer ) +FC_REFLECT(graphene::protocol::linear_vesting_policy_initializer, (begin_timestamp)(vesting_cliff_seconds)(vesting_duration_seconds) ) +FC_REFLECT(graphene::protocol::cdd_vesting_policy_initializer, (start_claim)(vesting_seconds) ) +FC_REFLECT(graphene::protocol::dormant_vesting_policy_initializer, ) +FC_REFLECT_TYPENAME( graphene::protocol::vesting_policy_initializer ) -FC_REFLECT_ENUM( graphene::chain::vesting_balance_type, (normal)(gpos)(son) ) +FC_REFLECT_ENUM( graphene::protocol::vesting_balance_type, (normal)(gpos)(son) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::vesting_balance_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::vesting_balance_withdraw_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::vesting_balance_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::vesting_balance_withdraw_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::vesting_balance_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::vesting_balance_withdraw_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::vesting_balance_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::vesting_balance_withdraw_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/vote.hpp b/libraries/protocol/include/graphene/protocol/vote.hpp similarity index 85% rename from libraries/chain/include/graphene/chain/protocol/vote.hpp rename to libraries/protocol/include/graphene/protocol/vote.hpp index 8a46954d..1553b473 100644 --- a/libraries/chain/include/graphene/chain/protocol/vote.hpp +++ b/libraries/protocol/include/graphene/protocol/vote.hpp @@ -24,9 +24,9 @@ #pragma once -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @brief An ID for some votable object @@ -126,25 +126,22 @@ struct vote_id_type } }; -class global_property_object; - -vote_id_type get_next_vote_id( global_property_object& gpo, vote_id_type::vote_type type ); - -} } // graphene::chain +} } // graphene::protocol namespace fc { class variant; -void to_variant( const graphene::chain::vote_id_type& var, fc::variant& vo, uint32_t max_depth = 1 ); -void from_variant( const fc::variant& var, graphene::chain::vote_id_type& vo, uint32_t max_depth = 1 ); +void to_variant( const graphene::protocol::vote_id_type& var, fc::variant& vo, uint32_t max_depth = 1 ); +void from_variant( const fc::variant& var, graphene::protocol::vote_id_type& vo, uint32_t max_depth = 1 ); } // fc -FC_REFLECT_TYPENAME( fc::flat_set ) +FC_REFLECT_TYPENAME( fc::flat_set ) -FC_REFLECT_ENUM( graphene::chain::vote_id_type::vote_type, (witness)(committee)(worker)(son)(VOTE_TYPE_COUNT) ) -FC_REFLECT( graphene::chain::vote_id_type, (content) ) +FC_REFLECT_ENUM( graphene::protocol::vote_id_type::vote_type, (witness)(committee)(worker)(son)(VOTE_TYPE_COUNT) ) +FC_REFLECT( graphene::protocol::vote_id_type, (content) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::vote_id_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::vote_id_type ) diff --git a/libraries/chain/include/graphene/chain/protocol/withdraw_permission.hpp b/libraries/protocol/include/graphene/protocol/withdraw_permission.hpp similarity index 80% rename from libraries/chain/include/graphene/chain/protocol/withdraw_permission.hpp rename to libraries/protocol/include/graphene/protocol/withdraw_permission.hpp index 7963e99f..3d2280a2 100644 --- a/libraries/chain/include/graphene/chain/protocol/withdraw_permission.hpp +++ b/libraries/protocol/include/graphene/protocol/withdraw_permission.hpp @@ -22,11 +22,11 @@ * THE SOFTWARE. */ #pragma once -#include -#include -#include +#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @brief Create a new withdrawal permission @@ -166,26 +166,27 @@ namespace graphene { namespace chain { void validate()const; }; -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::withdraw_permission_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::withdraw_permission_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::withdraw_permission_claim_operation::fee_parameters_type, (fee)(price_per_kbyte) ) -FC_REFLECT( graphene::chain::withdraw_permission_delete_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::withdraw_permission_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::withdraw_permission_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::withdraw_permission_claim_operation::fee_parameters_type, (fee)(price_per_kbyte) ) +FC_REFLECT( graphene::protocol::withdraw_permission_delete_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::withdraw_permission_create_operation, (fee)(withdraw_from_account)(authorized_account) +FC_REFLECT( graphene::protocol::withdraw_permission_create_operation, (fee)(withdraw_from_account)(authorized_account) (withdrawal_limit)(withdrawal_period_sec)(periods_until_expiration)(period_start_time) ) -FC_REFLECT( graphene::chain::withdraw_permission_update_operation, (fee)(withdraw_from_account)(authorized_account) +FC_REFLECT( graphene::protocol::withdraw_permission_update_operation, (fee)(withdraw_from_account)(authorized_account) (permission_to_update)(withdrawal_limit)(withdrawal_period_sec)(period_start_time)(periods_until_expiration) ) -FC_REFLECT( graphene::chain::withdraw_permission_claim_operation, (fee)(withdraw_permission)(withdraw_from_account)(withdraw_to_account)(amount_to_withdraw)(memo) ); -FC_REFLECT( graphene::chain::withdraw_permission_delete_operation, (fee)(withdraw_from_account)(authorized_account) +FC_REFLECT( graphene::protocol::withdraw_permission_claim_operation, (fee)(withdraw_permission)(withdraw_from_account)(withdraw_to_account)(amount_to_withdraw)(memo) ); +FC_REFLECT( graphene::protocol::withdraw_permission_delete_operation, (fee)(withdraw_from_account)(authorized_account) (withdrawal_permission) ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::withdraw_permission_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::withdraw_permission_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::withdraw_permission_claim_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::withdraw_permission_delete_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::withdraw_permission_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::withdraw_permission_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::withdraw_permission_claim_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::withdraw_permission_delete_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::withdraw_permission_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::withdraw_permission_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::withdraw_permission_claim_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::withdraw_permission_delete_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::withdraw_permission_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::withdraw_permission_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::withdraw_permission_claim_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::withdraw_permission_delete_operation ) + diff --git a/libraries/chain/include/graphene/chain/protocol/witness.hpp b/libraries/protocol/include/graphene/protocol/witness.hpp similarity index 75% rename from libraries/chain/include/graphene/chain/protocol/witness.hpp rename to libraries/protocol/include/graphene/protocol/witness.hpp index 2b5e88b0..466295c7 100644 --- a/libraries/chain/include/graphene/chain/protocol/witness.hpp +++ b/libraries/protocol/include/graphene/protocol/witness.hpp @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @brief Create a witness object, as a bid to hold a witness position on the network. @@ -78,15 +78,16 @@ namespace graphene { namespace chain { /// TODO: witness_resign_operation : public base_operation -} } // graphene::chain +} } // graphene::protocol -FC_REFLECT( graphene::chain::witness_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::witness_create_operation, (fee)(witness_account)(url)(block_signing_key)(initial_secret) ) +FC_REFLECT( graphene::protocol::witness_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::witness_create_operation, (fee)(witness_account)(url)(block_signing_key)(initial_secret) ) -FC_REFLECT( graphene::chain::witness_update_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::witness_update_operation, (fee)(witness)(witness_account)(new_url)(new_signing_key)(new_initial_secret) ) +FC_REFLECT( graphene::protocol::witness_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::witness_update_operation, (fee)(witness)(witness_account)(new_url)(new_signing_key)(new_initial_secret) ) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::witness_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::witness_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::witness_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::witness_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::witness_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::witness_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::witness_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::witness_update_operation ) diff --git a/libraries/chain/include/graphene/chain/protocol/worker.hpp b/libraries/protocol/include/graphene/protocol/worker.hpp similarity index 84% rename from libraries/chain/include/graphene/chain/protocol/worker.hpp rename to libraries/protocol/include/graphene/protocol/worker.hpp index 11e0aa05..22fe0b54 100644 --- a/libraries/chain/include/graphene/chain/protocol/worker.hpp +++ b/libraries/protocol/include/graphene/protocol/worker.hpp @@ -22,10 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { /** * @defgroup workers The Blockchain Worker System @@ -96,14 +96,15 @@ namespace graphene { namespace chain { } } -FC_REFLECT( graphene::chain::vesting_balance_worker_initializer, (pay_vesting_period_days) ) -FC_REFLECT( graphene::chain::burn_worker_initializer, ) -FC_REFLECT( graphene::chain::refund_worker_initializer, ) -FC_REFLECT_TYPENAME( graphene::chain::worker_initializer ) +FC_REFLECT( graphene::protocol::vesting_balance_worker_initializer, (pay_vesting_period_days) ) +FC_REFLECT( graphene::protocol::burn_worker_initializer, ) +FC_REFLECT( graphene::protocol::refund_worker_initializer, ) +FC_REFLECT_TYPENAME( graphene::protocol::worker_initializer ) -FC_REFLECT( graphene::chain::worker_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::worker_create_operation, +FC_REFLECT( graphene::protocol::worker_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::protocol::worker_create_operation, (fee)(owner)(work_begin_date)(work_end_date)(daily_pay)(name)(url)(initializer) ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::worker_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::worker_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::worker_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::protocol::worker_create_operation ) + diff --git a/libraries/chain/protocol/lottery_ops.cpp b/libraries/protocol/lottery_ops.cpp similarity index 91% rename from libraries/chain/protocol/lottery_ops.cpp rename to libraries/protocol/lottery_ops.cpp index d4f11fc4..090ab556 100644 --- a/libraries/chain/protocol/lottery_ops.cpp +++ b/libraries/protocol/lottery_ops.cpp @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void ticket_purchase_operation::validate() const { @@ -36,4 +36,4 @@ share_type ticket_purchase_operation::calculate_fee( const fee_parameters_type& return k.fee; } -} } // namespace graphene::chain +} } // namespace graphene::protocol diff --git a/libraries/chain/protocol/market.cpp b/libraries/protocol/market.cpp similarity index 66% rename from libraries/chain/protocol/market.cpp rename to libraries/protocol/market.cpp index ae0a3a68..87efa0b9 100644 --- a/libraries/chain/protocol/market.cpp +++ b/libraries/protocol/market.cpp @@ -21,10 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include +#include + #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void limit_order_create_operation::validate()const { @@ -46,12 +48,13 @@ void call_order_update_operation::validate()const FC_ASSERT( delta_collateral.amount != 0 || delta_debt.amount != 0 ); } FC_CAPTURE_AND_RETHROW((*this)) } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::limit_order_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::limit_order_cancel_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::call_order_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::limit_order_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::limit_order_cancel_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::call_order_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::fill_order_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::limit_order_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::limit_order_cancel_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::call_order_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::limit_order_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::limit_order_cancel_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::call_order_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::fill_order_operation ) diff --git a/libraries/chain/protocol/memo.cpp b/libraries/protocol/memo.cpp similarity index 84% rename from libraries/chain/protocol/memo.cpp rename to libraries/protocol/memo.cpp index 4e863a87..185d3f9e 100644 --- a/libraries/chain/protocol/memo.cpp +++ b/libraries/protocol/memo.cpp @@ -21,11 +21,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include + +#include + #include #include -namespace graphene { namespace chain { +#include + +namespace graphene { namespace protocol { void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::public_key& pub, const string& msg, uint64_t custom_nonce) @@ -39,7 +43,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub to = pub; if( custom_nonce == 0 ) { - uint64_t entropy = fc::sha224::hash(fc::ecc::private_key::generate())._hash[0]; + uint64_t entropy = fc::sha224::hash(fc::ecc::private_key::generate())._hash[0].value(); entropy <<= 32; entropy &= 0xff00000000000000; nonce = (fc::time_point::now().time_since_epoch().count() & 0x00ffffffffffffff) | entropy; @@ -47,7 +51,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub nonce = custom_nonce; auto secret = priv.get_shared_secret(pub); auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str()); - string text = memo_message(digest_type::hash(msg)._hash[0], msg).serialize(); + string text = memo_message(digest_type::hash(msg)._hash[0].value(), msg).serialize(); message = fc::aes_encrypt( nonce_plus_secret, vector(text.begin(), text.end()) ); } else @@ -67,7 +71,7 @@ string memo_data::get_message(const fc::ecc::private_key& priv, auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str()); auto plain_text = fc::aes_decrypt( nonce_plus_secret, message ); auto result = memo_message::deserialize(string(plain_text.begin(), plain_text.end())); - FC_ASSERT( result.checksum == uint32_t(digest_type::hash(result.text)._hash[0]) ); + FC_ASSERT( result.checksum == (uint32_t)digest_type::hash(result.text)._hash[0].value() ); return result.text; } else @@ -79,7 +83,7 @@ string memo_data::get_message(const fc::ecc::private_key& priv, string memo_message::serialize() const { auto serial_checksum = string(sizeof(checksum), ' '); - (uint32_t&)(*serial_checksum.data()) = checksum; + (uint32_t&)(*serial_checksum.data()) = boost::endian::native_to_little(checksum); return serial_checksum + text; } @@ -87,12 +91,13 @@ memo_message memo_message::deserialize(const string& serial) { memo_message result; FC_ASSERT( serial.size() >= sizeof(result.checksum) ); - result.checksum = ((uint32_t&)(*serial.data())); + result.checksum = boost::endian::little_to_native((uint32_t&)(*serial.data())); result.text = serial.substr(sizeof(result.checksum)); return result; } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::memo_message ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::memo_data ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::memo_message ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::memo_data ) diff --git a/libraries/chain/protocol/nft.cpp b/libraries/protocol/nft.cpp similarity index 95% rename from libraries/chain/protocol/nft.cpp rename to libraries/protocol/nft.cpp index ca7fe816..5d011e4b 100644 --- a/libraries/chain/protocol/nft.cpp +++ b/libraries/protocol/nft.cpp @@ -1,9 +1,9 @@ -#include -#include +#include +#include namespace graphene { -namespace chain +namespace protocol { bool is_valid_nft_token_name(const string &name) @@ -95,5 +95,5 @@ share_type nft_set_approval_for_all_operation::calculate_fee(const fee_parameter return k.fee; } -} // namespace chain +} // namespace protocol } // namespace graphene diff --git a/libraries/chain/protocol/nft_lottery.cpp b/libraries/protocol/nft_lottery.cpp similarity index 82% rename from libraries/chain/protocol/nft_lottery.cpp rename to libraries/protocol/nft_lottery.cpp index 16454962..276fdca5 100644 --- a/libraries/chain/protocol/nft_lottery.cpp +++ b/libraries/protocol/nft_lottery.cpp @@ -1,10 +1,10 @@ -#include -#include -#include +#include +#include +#include namespace graphene { - namespace chain + namespace protocol { void nft_lottery_options::validate() const @@ -34,5 +34,5 @@ namespace graphene FC_ASSERT(fee.amount >= 0, "Fee must not be negative"); FC_ASSERT(tickets_to_buy > 0); } - } // namespace chain -} // namespace graphene \ No newline at end of file + } // namespace protocol +} // namespace graphene diff --git a/libraries/chain/protocol/offer.cpp b/libraries/protocol/offer.cpp similarity index 93% rename from libraries/chain/protocol/offer.cpp rename to libraries/protocol/offer.cpp index e83af3f8..aefb813e 100644 --- a/libraries/chain/protocol/offer.cpp +++ b/libraries/protocol/offer.cpp @@ -1,9 +1,9 @@ -#include +#include #include namespace graphene { - namespace chain + namespace protocol { share_type offer_operation::calculate_fee(const fee_parameters_type &schedule) const { @@ -53,5 +53,5 @@ namespace graphene return core_fee_required; } - } // namespace chain -} // namespace graphene \ No newline at end of file + } // namespace protocol +} // namespace graphene diff --git a/libraries/chain/protocol/operations.cpp b/libraries/protocol/operations.cpp similarity index 89% rename from libraries/chain/protocol/operations.cpp rename to libraries/protocol/operations.cpp index 99c8a376..b36c3651 100644 --- a/libraries/chain/protocol/operations.cpp +++ b/libraries/protocol/operations.cpp @@ -21,17 +21,20 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include -#include +#include +#include -namespace graphene { namespace chain { +#include +#include +#include + +namespace graphene { namespace protocol { uint64_t base_operation::calculate_data_fee( uint64_t bytes, uint64_t price_per_kbyte ) { - auto result = (fc::uint128(bytes) * price_per_kbyte) / 1024; + auto result = (fc::uint128_t(bytes) * price_per_kbyte) / 1024; FC_ASSERT( result <= GRAPHENE_MAX_SHARE_SUPPLY ); - return result.to_uint64(); + return result; } void balance_claim_operation::validate()const @@ -100,6 +103,7 @@ void operation_get_required_authorities( const operation& op, op.visit( operation_get_required_auth( active, owner, other, ignore_custom_operation_required_auths ) ); } -} } // namespace graphene::chain +} } // namespace graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::op_wrapper ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::op_wrapper ) diff --git a/libraries/chain/protocol/proposal.cpp b/libraries/protocol/proposal.cpp similarity index 83% rename from libraries/chain/protocol/proposal.cpp rename to libraries/protocol/proposal.cpp index f14f057a..a1a40187 100644 --- a/libraries/chain/protocol/proposal.cpp +++ b/libraries/protocol/proposal.cpp @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include +#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { proposal_create_operation proposal_create_operation::committee_proposal(const chain_parameters& global_params, fc::time_point_sec head_block_time ) { @@ -105,11 +105,11 @@ void proposal_update_operation::get_required_owner_authorities( flat_set -#include +#include #include #include @@ -30,23 +29,20 @@ #include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { pts_address::pts_address() { - memset( addr.data, 0, sizeof(addr.data) ); + memset( addr.data(), 0, addr.size() ); } pts_address::pts_address( const std::string& base58str ) { std::vector v = fc::from_base58( fc::string(base58str) ); if( v.size() ) - memcpy( addr.data, v.data(), std::min( v.size(), sizeof(addr) ) ); + memcpy( addr.data(), v.data(), std::min( v.size(), addr.size() ) ); - if( !is_valid() ) - { - FC_THROW_EXCEPTION( invalid_pts_address, "invalid pts_address ${a}", ("a", base58str) ); - } + FC_ASSERT(is_valid(), "invalid pts_address ${a}", ("a", base58str)); } pts_address::pts_address( const fc::ecc::public_key& pub, bool compressed, uint8_t version ) @@ -55,19 +51,19 @@ namespace graphene { namespace chain { if( compressed ) { auto dat = pub.serialize(); - sha2 = fc::sha256::hash(dat.data, sizeof(dat) ); + sha2 = fc::sha256::hash((char*) dat.data(), dat.size() ); } else { auto dat = pub.serialize_ecc_point(); - sha2 = fc::sha256::hash(dat.data, sizeof(dat) ); + sha2 = fc::sha256::hash((char*) dat.data(), dat.size() ); } auto rep = fc::ripemd160::hash((char*)&sha2,sizeof(sha2)); - addr.data[0] = version; - memcpy( addr.data+1, (char*)&rep, sizeof(rep) ); - auto check = fc::sha256::hash( addr.data, sizeof(rep)+1 ); + addr[0] = version; + memcpy( addr.data() + 1, (char*)&rep, sizeof(rep) ); + auto check = fc::sha256::hash( addr.data(), sizeof(rep)+1 ); check = fc::sha256::hash(check); - memcpy( addr.data+1+sizeof(rep), (char*)&check, 4 ); + memcpy( addr.data() + 1 + sizeof(rep), (char*)&check, 4 ); } /** @@ -76,34 +72,34 @@ namespace graphene { namespace chain { */ bool pts_address::is_valid()const { - auto check = fc::sha256::hash( addr.data, sizeof(fc::ripemd160)+1 ); + auto check = fc::sha256::hash( addr.data(), sizeof(fc::ripemd160)+1 ); check = fc::sha256::hash(check); - return memcmp( addr.data+1+sizeof(fc::ripemd160), (char*)&check, 4 ) == 0; + return memcmp( addr.data() + 1 + sizeof(fc::ripemd160), (char*)&check, 4 ) == 0; } pts_address::operator std::string()const { - return fc::to_base58( addr.data, sizeof(addr) ); + return fc::to_base58( addr.data(), addr.size() ); } } } // namespace graphene namespace fc { - void to_variant( const graphene::chain::pts_address& var, variant& vo, uint32_t max_depth ) + void to_variant( const graphene::protocol::pts_address& var, variant& vo, uint32_t max_depth ) { vo = std::string(var); } - void from_variant( const variant& var, graphene::chain::pts_address& vo, uint32_t max_depth ) + void from_variant( const variant& var, graphene::protocol::pts_address& vo, uint32_t max_depth ) { - vo = graphene::chain::pts_address( var.as_string() ); + vo = graphene::protocol::pts_address( var.as_string() ); } namespace raw { - template void pack( datastream& s, const graphene::chain::pts_address& tx, + template void pack( datastream& s, const graphene::protocol::pts_address& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - template void pack( datastream& s, const graphene::chain::pts_address& tx, + template void pack( datastream& s, const graphene::protocol::pts_address& tx, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template void unpack( datastream& s, graphene::protocol::pts_address& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - template void unpack( datastream& s, graphene::chain::pts_address& tx, - uint32_t _max_depth=FC_PACK_MAX_DEPTH ); } } // fc::raw diff --git a/libraries/protocol/small_ops.cpp b/libraries/protocol/small_ops.cpp new file mode 100644 index 00000000..b870960a --- /dev/null +++ b/libraries/protocol/small_ops.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019 BitShares Blockchain Foundation, and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::balance_claim_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::buyback_account_options ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::fba_distribute_operation ) + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::vesting_balance_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::vesting_balance_withdraw_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::vesting_balance_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::vesting_balance_withdraw_operation ) + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::chain_parameters ) + +namespace graphene { namespace protocol { + +FC_IMPLEMENT_EXCEPTION( protocol_exception, 4000000, "protocol exception" ) + +FC_IMPLEMENT_DERIVED_EXCEPTION( transaction_exception, protocol_exception, 4010000, + "transaction validation exception" ) + +FC_IMPLEMENT_DERIVED_EXCEPTION( tx_missing_active_auth, transaction_exception, 4010001, + "missing required active authority" ) +FC_IMPLEMENT_DERIVED_EXCEPTION( tx_missing_owner_auth, transaction_exception, 4010002, + "missing required owner authority" ) +FC_IMPLEMENT_DERIVED_EXCEPTION( tx_missing_other_auth, transaction_exception, 4010003, + "missing required other authority" ) +FC_IMPLEMENT_DERIVED_EXCEPTION( tx_irrelevant_sig, transaction_exception, 4010004, + "irrelevant signature included" ) +FC_IMPLEMENT_DERIVED_EXCEPTION( tx_duplicate_sig, transaction_exception, 4010005, + "duplicate signature included" ) +FC_IMPLEMENT_DERIVED_EXCEPTION( invalid_committee_approval, transaction_exception, 4010006, + "committee account cannot directly approve transaction" ) +FC_IMPLEMENT_DERIVED_EXCEPTION( insufficient_fee, transaction_exception, 4010007, "insufficient fee" ) + +} } // graphene::protocol + diff --git a/libraries/chain/protocol/vote.cpp b/libraries/protocol/special_authority.cpp similarity index 62% rename from libraries/chain/protocol/vote.cpp rename to libraries/protocol/special_authority.cpp index 68f476f5..55e488cf 100644 --- a/libraries/chain/protocol/vote.cpp +++ b/libraries/protocol/special_authority.cpp @@ -22,32 +22,31 @@ * THE SOFTWARE. */ -#include -#include -#include +#include -namespace graphene { namespace chain { +#include -vote_id_type get_next_vote_id( global_property_object& gpo, vote_id_type::vote_type type ) +namespace graphene { namespace protocol { + +struct special_authority_validate_visitor { - return vote_id_type( type, gpo.next_available_vote_id++ ); + typedef void result_type; + + void operator()( const no_special_authority& a ) {} + + void operator()( const top_holders_special_authority& a ) + { + FC_ASSERT( a.num_top_holders > 0 ); + } +}; + +void validate_special_authority( const special_authority& a ) +{ + special_authority_validate_visitor vtor; + a.visit( vtor ); } -} } // graphene::chain +} } // graphene::protocol -namespace fc -{ +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::top_holders_special_authority ) -void to_variant( const graphene::chain::vote_id_type& var, variant& vo, uint32_t max_depth ) -{ - vo = string(var); -} - -void from_variant( const variant& var, graphene::chain::vote_id_type& vo, uint32_t max_depth ) -{ - vo = graphene::chain::vote_id_type(var.as_string()); -} - -} // fc - -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::vote_id_type ) diff --git a/libraries/chain/protocol/sport.cpp b/libraries/protocol/sport.cpp similarity index 93% rename from libraries/chain/protocol/sport.cpp rename to libraries/protocol/sport.cpp index a8fdbf2a..a7d52f8d 100644 --- a/libraries/chain/protocol/sport.cpp +++ b/libraries/protocol/sport.cpp @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void sport_create_operation::validate() const { @@ -40,5 +40,5 @@ void sport_delete_operation::validate() const FC_ASSERT( fee.amount >= 0 ); } -} } // graphene::chain +} } // graphene::protocol diff --git a/libraries/chain/protocol/tournament.cpp b/libraries/protocol/tournament.cpp similarity index 94% rename from libraries/chain/protocol/tournament.cpp rename to libraries/protocol/tournament.cpp index 78ab4c01..33ca25de 100644 --- a/libraries/chain/protocol/tournament.cpp +++ b/libraries/protocol/tournament.cpp @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void tournament_options::validate() const { @@ -73,4 +73,4 @@ void game_move_operation::validate()const { } -} } // namespace graphene::chain +} } // namespace graphene::protocol diff --git a/libraries/chain/protocol/transaction.cpp b/libraries/protocol/transaction.cpp similarity index 91% rename from libraries/chain/protocol/transaction.cpp rename to libraries/protocol/transaction.cpp index 4c0684bd..903b9672 100644 --- a/libraries/chain/protocol/transaction.cpp +++ b/libraries/protocol/transaction.cpp @@ -21,14 +21,18 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include + +#include +#include +#include +#include +#include + #include -#include #include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { digest_type processed_transaction::merkle_digest()const { @@ -59,7 +63,7 @@ void transaction::validate() const operation_validate(op); } -graphene::chain::transaction_id_type graphene::chain::transaction::id() const +graphene::protocol::transaction_id_type graphene::protocol::transaction::id() const { auto h = digest(); transaction_id_type result; @@ -67,7 +71,7 @@ graphene::chain::transaction_id_type graphene::chain::transaction::id() const return result; } -const signature_type& graphene::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id) +const signature_type& graphene::protocol::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id) { digest_type h = sig_digest( chain_id ); signatures.push_back(key.sign_compact(h)); @@ -75,7 +79,7 @@ const signature_type& graphene::chain::signed_transaction::sign(const private_ke return signatures.back(); } -signature_type graphene::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const +signature_type graphene::protocol::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const { digest_type::encoder enc; fc::raw::pack( enc, chain_id ); @@ -90,8 +94,8 @@ void transaction::set_expiration( fc::time_point_sec expiration_time ) void transaction::set_reference_block( const block_id_type& reference_block ) { - ref_block_num = fc::endian_reverse_u32(reference_block._hash[0]); - ref_block_prefix = reference_block._hash[1]; + ref_block_num = boost::endian::endian_reverse(reference_block._hash[0].value()); + ref_block_prefix = reference_block._hash[1].value(); } void transaction::get_required_authorities( flat_set& active, @@ -261,8 +265,9 @@ void verify_authority( const vector& ops, const flat_set required_active; flat_set required_owner; vector other; + flat_set available_keys; - sign_state s(sigs,get_active); + sign_state s(sigs,get_active, available_keys); s.max_recursion = max_recursion_depth; for( auto& id : active_aprovals ) s.approved_by.insert( id ); @@ -426,8 +431,8 @@ set signed_transaction::minimize_required_signatures( result.erase( k ); try { - graphene::chain::verify_authority( operations, result, get_active, get_owner, get_custom, - ignore_custom_operation_required_auths, max_recursion ); + graphene::protocol::verify_authority( operations, result, get_active, get_owner, get_custom, + ignore_custom_operation_required_auths, max_recursion ); continue; // element stays erased if verify_authority is ok } catch( const tx_missing_owner_auth& e ) {} @@ -446,11 +451,13 @@ void signed_transaction::verify_authority( bool ignore_custom_operation_required_auths, uint32_t max_recursion )const { try { - graphene::chain::verify_authority( operations, get_signature_keys( chain_id ), get_active, get_owner, get_custom, ignore_custom_operation_required_auths, max_recursion ); + graphene::protocol::verify_authority( operations, get_signature_keys( chain_id ), get_active, get_owner, + get_custom, ignore_custom_operation_required_auths, max_recursion ); } FC_CAPTURE_AND_RETHROW( (*this) ) } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::protocol::transaction) +GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::protocol::signed_transaction) +GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::protocol::processed_transaction) -GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::transaction) -GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::signed_transaction) -GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::processed_transaction) diff --git a/libraries/chain/protocol/transfer.cpp b/libraries/protocol/transfer.cpp similarity index 79% rename from libraries/chain/protocol/transfer.cpp rename to libraries/protocol/transfer.cpp index 0fb0aefa..369b7ce4 100644 --- a/libraries/chain/protocol/transfer.cpp +++ b/libraries/protocol/transfer.cpp @@ -21,11 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { share_type transfer_operation::calculate_fee( const fee_parameters_type& schedule )const { @@ -62,9 +62,10 @@ void override_transfer_operation::validate()const FC_ASSERT( issuer != from ); } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::transfer_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::override_transfer_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::transfer_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::override_transfer_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::transfer_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::override_transfer_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::transfer_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::override_transfer_operation ) diff --git a/libraries/protocol/types.cpp b/libraries/protocol/types.cpp new file mode 100644 index 00000000..88f224e3 --- /dev/null +++ b/libraries/protocol/types.cpp @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +#include +#include +#include +#include + +namespace graphene { namespace protocol { + + public_key_type::public_key_type():key_data(){}; + + public_key_type::public_key_type( const fc::ecc::public_key_data& data ) + :key_data( data ) {}; + + public_key_type::public_key_type( const fc::ecc::public_key& pubkey ) + :key_data( pubkey ) {}; + + public_key_type::public_key_type( const std::string& base58str ) + { + // TODO: Refactor syntactic checks into static is_valid() + // to make public_key_type API more similar to address API + std::string prefix( GRAPHENE_ADDRESS_PREFIX ); + + // TODO: This is temporary for testing + try + { + if( is_valid_v1( base58str ) ) + prefix = std::string( "BTS" ); + } + catch( ... ) + { + } + + try + { + if( is_valid_muse( base58str ) ) + prefix = std::string( "MUSE" ); + } + catch( ... ) + { + } + + const size_t prefix_len = prefix.size(); + FC_ASSERT( base58str.size() > prefix_len ); + FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); + auto bin = fc::from_base58( base58str.substr( prefix_len ) ); + auto bin_key = fc::raw::unpack(bin); + key_data = bin_key.data; + FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0].value() == bin_key.check ); + }; + + bool public_key_type::is_valid_muse( const std::string& base58str ) + { + std::string prefix( "MUSE" ); + + const size_t prefix_len = prefix.size(); + FC_ASSERT( base58str.size() > prefix_len ); + FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); + auto bin = fc::from_base58( base58str.substr( prefix_len ) ); + auto bin_key = fc::raw::unpack(bin); + key_data = bin_key.data; + FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0].value() == bin_key.check ); + return true; + } + + // TODO: This is temporary for testing + bool public_key_type::is_valid_v1( const std::string& base58str ) + { + std::string prefix( "BTS" ); + const size_t prefix_len = prefix.size(); + FC_ASSERT( base58str.size() > prefix_len ); + FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); + auto bin = fc::from_base58( base58str.substr( prefix_len ) ); + auto bin_key = fc::raw::unpack(bin); + fc::ecc::public_key_data key_data = bin_key.data; + FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0].value() == bin_key.check ); + return true; + } + + public_key_type::operator fc::ecc::public_key_data() const + { + return key_data; + }; + + public_key_type::operator fc::ecc::public_key() const + { + return fc::ecc::public_key( key_data ); + }; + + public_key_type::operator std::string() const + { + binary_key k; + k.data = key_data; + k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0].value(); + auto data = fc::raw::pack( k ); + return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() ); + } + + bool operator == ( const public_key_type& p1, const fc::ecc::public_key& p2) + { + return p1.key_data == p2.serialize(); + } + + bool operator == ( const public_key_type& p1, const public_key_type& p2) + { + return p1.key_data == p2.key_data; + } + + bool operator != ( const public_key_type& p1, const public_key_type& p2) + { + return p1.key_data != p2.key_data; + } + +} } // graphene::protocol + +namespace fc +{ + using namespace std; + void to_variant( const graphene::protocol::public_key_type& var, fc::variant& vo, uint32_t max_depth ) + { + vo = std::string( var ); + } + + void from_variant( const fc::variant& var, graphene::protocol::public_key_type& vo, uint32_t max_depth ) + { + vo = graphene::protocol::public_key_type( var.as_string() ); + } + + void from_variant( const fc::variant& var, std::shared_ptr& vo, + uint32_t max_depth ) { + // If it's null, just make a new one + if (!vo) vo = std::make_shared(); + // Convert the non-const shared_ptr to a non-const fee_schedule& so we can write it + // Don't decrement max_depth since we're not actually deserializing at this step + from_variant(var, const_cast(*vo), max_depth); + } + +namespace raw { + template void pack( datastream& s, const graphene::protocol::public_key_type& tx, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template void pack( datastream& s, const graphene::protocol::public_key_type& tx, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template void unpack( datastream& s, graphene::protocol::public_key_type& tx, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); +} } // fc::raw diff --git a/libraries/chain/include/graphene/chain/protocol/config.hpp b/libraries/protocol/vote.cpp similarity index 72% rename from libraries/chain/include/graphene/chain/protocol/config.hpp rename to libraries/protocol/vote.cpp index 870b08fe..bd619d18 100644 --- a/libraries/chain/include/graphene/chain/protocol/config.hpp +++ b/libraries/protocol/vote.cpp @@ -21,5 +21,23 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#pragma once -#include + +#include + +namespace fc +{ + +void to_variant( const graphene::protocol::vote_id_type& var, variant& vo, uint32_t max_depth ) +{ + vo = string(var); +} + +void from_variant( const variant& var, graphene::protocol::vote_id_type& vo, uint32_t max_depth ) +{ + vo = graphene::protocol::vote_id_type(var.as_string()); +} + +} // fc + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::vote_id_type ) + diff --git a/libraries/chain/protocol/withdraw_permission.cpp b/libraries/protocol/withdraw_permission.cpp similarity index 69% rename from libraries/chain/protocol/withdraw_permission.cpp rename to libraries/protocol/withdraw_permission.cpp index b36c378d..f39927ba 100644 --- a/libraries/chain/protocol/withdraw_permission.cpp +++ b/libraries/protocol/withdraw_permission.cpp @@ -21,11 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void withdraw_permission_update_operation::validate()const { @@ -67,13 +67,14 @@ void withdraw_permission_delete_operation::validate() const FC_ASSERT( withdraw_from_account != authorized_account ); } -} } // graphene::chain +} } // graphene::protocol + +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::withdraw_permission_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::withdraw_permission_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::withdraw_permission_claim_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::withdraw_permission_delete_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::withdraw_permission_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::withdraw_permission_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::withdraw_permission_claim_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::withdraw_permission_delete_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_claim_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_delete_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_update_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_claim_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::withdraw_permission_delete_operation ) diff --git a/libraries/chain/protocol/witness.cpp b/libraries/protocol/witness.cpp similarity index 73% rename from libraries/chain/protocol/witness.cpp rename to libraries/protocol/witness.cpp index 90583cd8..91915323 100644 --- a/libraries/chain/protocol/witness.cpp +++ b/libraries/protocol/witness.cpp @@ -21,10 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include + #include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void witness_create_operation::validate() const { @@ -39,9 +40,9 @@ void witness_update_operation::validate() const FC_ASSERT(new_url->size() < GRAPHENE_MAX_URL_LENGTH ); } -} } // graphene::chain +} } // graphene::protocol -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_update_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_create_operation ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_update_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::witness_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::witness_update_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::witness_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::witness_update_operation ) diff --git a/libraries/chain/protocol/worker.cpp b/libraries/protocol/worker.cpp similarity index 83% rename from libraries/chain/protocol/worker.cpp rename to libraries/protocol/worker.cpp index 932148ec..44d7f1b1 100644 --- a/libraries/chain/protocol/worker.cpp +++ b/libraries/protocol/worker.cpp @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include #include +#include -namespace graphene { namespace chain { +namespace graphene { namespace protocol { void worker_create_operation::validate() const { @@ -38,5 +38,6 @@ void worker_create_operation::validate() const } } -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_create_operation::fee_parameters_type ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_create_operation ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::worker_create_operation::fee_parameters_type ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::worker_create_operation ) + diff --git a/libraries/time/CMakeLists.txt b/libraries/time/CMakeLists.txt deleted file mode 100644 index cc8a909d..00000000 --- a/libraries/time/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -file(GLOB HEADERS "include/graphene/time/*.hpp") - -add_library( graphene_time - time.cpp - ) - -target_link_libraries( graphene_time fc ) -target_include_directories( graphene_time - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) - -install( TARGETS - graphene_time - - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib -) diff --git a/libraries/time/include/graphene/time/time.hpp b/libraries/time/include/graphene/time/time.hpp deleted file mode 100644 index 2979369c..00000000 --- a/libraries/time/include/graphene/time/time.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#pragma once - -#include -#include -#include - -namespace graphene { namespace time { - - typedef fc::signal time_discontinuity_signal_type; - extern time_discontinuity_signal_type time_discontinuity_signal; - - fc::optional ntp_time(); - fc::time_point now(); - fc::time_point nonblocking_now(); // identical to now() but guaranteed not to block - void update_ntp_time(); - fc::microseconds ntp_error(); - void shutdown_ntp_time(); - - void start_simulated_time( const fc::time_point sim_time ); - void advance_simulated_time_to( const fc::time_point sim_time ); - void advance_time( int32_t delta_seconds ); - -} } // graphene::time diff --git a/libraries/time/time.cpp b/libraries/time/time.cpp deleted file mode 100644 index 6ba0c126..00000000 --- a/libraries/time/time.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include -#include -#include -#include - -#include - -namespace graphene { namespace time { - -static int32_t simulated_time = 0; -static int32_t adjusted_time_sec = 0; - -time_discontinuity_signal_type time_discontinuity_signal; - -namespace detail -{ - std::atomic ntp_service(nullptr); - fc::mutex ntp_service_initialization_mutex; -} - -fc::optional ntp_time() -{ - fc::ntp* actual_ntp_service = detail::ntp_service.load(); - if (!actual_ntp_service) - { - fc::scoped_lock lock(detail::ntp_service_initialization_mutex); - actual_ntp_service = detail::ntp_service.load(); - if (!actual_ntp_service) - { - actual_ntp_service = new fc::ntp; - detail::ntp_service.store(actual_ntp_service); - } - } - return actual_ntp_service->get_time(); -} - -void shutdown_ntp_time() -{ - fc::ntp* actual_ntp_service = detail::ntp_service.exchange(nullptr); - delete actual_ntp_service; -} - -fc::time_point now() -{ - if( simulated_time ) - return fc::time_point() + fc::seconds( simulated_time + adjusted_time_sec ); - - fc::optional current_ntp_time = ntp_time(); - if( current_ntp_time.valid() ) - return *current_ntp_time + fc::seconds( adjusted_time_sec ); - else - return fc::time_point::now() + fc::seconds( adjusted_time_sec ); -} - -fc::time_point nonblocking_now() -{ - if (simulated_time) - return fc::time_point() + fc::seconds(simulated_time + adjusted_time_sec); - - fc::ntp* actual_ntp_service = detail::ntp_service.load(); - fc::optional current_ntp_time; - if (actual_ntp_service) - current_ntp_time = actual_ntp_service->get_time(); - - if (current_ntp_time) - return *current_ntp_time + fc::seconds(adjusted_time_sec); - else - return fc::time_point::now() + fc::seconds(adjusted_time_sec); -} - -void update_ntp_time() -{ - detail::ntp_service.load()->request_now(); -} - -fc::microseconds ntp_error() -{ - fc::optional current_ntp_time = ntp_time(); - FC_ASSERT( current_ntp_time, "We don't have NTP time!" ); - return *current_ntp_time - fc::time_point::now(); -} - -void start_simulated_time( const fc::time_point sim_time ) -{ - simulated_time = sim_time.sec_since_epoch(); - adjusted_time_sec = 0; -} -void advance_simulated_time_to( const fc::time_point sim_time ) -{ - simulated_time = sim_time.sec_since_epoch(); - adjusted_time_sec = 0; -} - -void advance_time( int32_t delta_seconds ) -{ - adjusted_time_sec += delta_seconds; - time_discontinuity_signal(); -} - -} } // graphene::time diff --git a/libraries/utilities/CMakeLists.txt b/libraries/utilities/CMakeLists.txt index 98086b10..e58ff332 100644 --- a/libraries/utilities/CMakeLists.txt +++ b/libraries/utilities/CMakeLists.txt @@ -20,10 +20,17 @@ set(sources configure_file("${CMAKE_CURRENT_SOURCE_DIR}/git_revision.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp" @ONLY) list(APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp") -add_library( graphene_utilities - ${sources} - ${HEADERS} ) -target_link_libraries( graphene_utilities fc ) +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_utilities + ${sources} + ${HEADERS} ) +else() + add_library( graphene_utilities SHARED + ${sources} + ${HEADERS} ) +endif() + +target_link_libraries( graphene_utilities fc curl ) target_include_directories( graphene_utilities PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) if (USE_PCH) diff --git a/libraries/wallet/include/graphene/wallet/reflect_util.hpp b/libraries/wallet/include/graphene/wallet/reflect_util.hpp index 44c0f412..28473391 100644 --- a/libraries/wallet/include/graphene/wallet/reflect_util.hpp +++ b/libraries/wallet/include/graphene/wallet/reflect_util.hpp @@ -39,9 +39,9 @@ namespace impl { std::string clean_name( const std::string& name ) { - const static std::string prefix = "graphene::chain::"; + const static std::string prefix = "graphene::protocol::"; const static std::string suffix = "_operation"; - // graphene::chain::.*_operation + // graphene::protocol::.*_operation if( (name.size() >= prefix.size() + suffix.size()) && (name.substr( 0, prefix.size() ) == prefix) && (name.substr( name.size()-suffix.size(), suffix.size() ) == suffix ) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index ff32ac10..c6048e09 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -2465,6 +2465,9 @@ class wallet_api bool broadcast); vector get_account_roles_by_owner(string owner_account_id_or_name) const; + signed_transaction run_custom_operation(string payer_id_or_name, std::vector required_auths, + string data, uint16_t id=0, bool broadcast=false); + void dbg_make_uia(string creator, string symbol); void dbg_make_mia(string creator, string symbol); void dbg_push_blocks( std::string src_filename, uint32_t count ); @@ -2795,4 +2798,5 @@ FC_API( graphene::wallet::wallet_api, (get_custom_account_authorities_by_permission_id) (get_custom_account_authorities_by_permission_name) (get_active_custom_account_authorities_by_operation) + (run_custom_operation) ) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index ae8b350e..1f38853f 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -63,20 +63,26 @@ #include #include #include +#include +#include +#include #include #include +#include #include #include #include -#include +#include #include #include -#include +#include -#include +#include +#include +#include #include #include #include @@ -165,7 +171,7 @@ optional maybe_id( const string& name_or_id ) string address_to_shorthash( const address& addr ) { - uint32_t x = addr.addr._hash[0]; + uint32_t x = addr.addr._hash[0].value(); static const char hd[] = "0123456789abcdef"; string result; @@ -369,7 +375,7 @@ private: // return true if any of my_accounts are players in this tournament bool tournament_is_relevant_to_my_accounts(const tournament_object& tournament_obj) { - tournament_details_object tournament_details = get_object(tournament_obj.tournament_details_id); + tournament_details_object tournament_details = get_object(tournament_obj.tournament_details_id); for (const account_object& account_obj : _wallet.my_accounts) if (tournament_details.registered_players.find(account_obj.id) != tournament_details.registered_players.end()) return true; @@ -654,14 +660,14 @@ public: return _checksum == fc::sha512(); } - template - T get_object(object_id id)const + template + graphene::db::object_downcast_t get_object(ID id)const { auto ob = _remote_db->get_objects({id}).front(); - return ob.template as( GRAPHENE_MAX_NESTED_OBJECTS ); + return ob.template as>( GRAPHENE_MAX_NESTED_OBJECTS ); } - void set_operation_fees( signed_transaction& tx, std::shared_ptr s ) + void set_operation_fees( signed_transaction& tx, const std::shared_ptr s ) { for( auto& op : tx.operations ) s->set_fee(op); @@ -680,7 +686,9 @@ public: " old"); result["next_maintenance_time"] = fc::get_approximate_relative_time_string(dynamic_props.next_maintenance_time); result["chain_id"] = chain_props.chain_id; - result["participation"] = (100*dynamic_props.recent_slots_filled.popcount()) / 128.0; + stringstream participation; + participation << fixed << std::setprecision(2) << (100.0*fc::popcount(dynamic_props.recent_slots_filled)) / 128.0; + result["participation"] = participation.str(); result["active_witnesses"] = fc::variant(global_props.active_witnesses, GRAPHENE_MAX_NESTED_OBJECTS); result["active_committee_members"] = fc::variant(global_props.active_committee_members, GRAPHENE_MAX_NESTED_OBJECTS); result["active_sons"] = fc::variant(global_props.active_sons, GRAPHENE_MAX_NESTED_OBJECTS); @@ -966,7 +974,7 @@ public: ("match", match_obj.id)("account", get_account(account_id).name)); for (const game_id_type& game_id : match_obj.games) { - game_object game_obj = get_object(game_id); + game_object game_obj = get_object(game_id); auto insert_result = game_cache.insert(game_obj); if (insert_result.second) game_in_new_state(game_obj); @@ -980,10 +988,10 @@ public: // updates on those matches void monitor_matches_in_tournament(const tournament_object& tournament_obj) { try { - tournament_details_object tournament_details = get_object(tournament_obj.tournament_details_id); + tournament_details_object tournament_details = get_object(tournament_obj.tournament_details_id); for (const match_id_type& match_id : tournament_details.matches) { - match_object match_obj = get_object(match_id); + match_object match_obj = get_object(match_id); auto insert_result = match_cache.insert(match_obj); if (insert_result.second) match_in_new_state(match_obj); @@ -1005,7 +1013,7 @@ public: { try { - tournament_object tournament = get_object(tournament_id); + tournament_object tournament = get_object(tournament_id); auto insert_result = tournament_cache.insert(tournament); if (insert_result.second) { @@ -1190,7 +1198,7 @@ public: total_fee += gprops.current_fees->set_fee( op, fee_asset_obj.options.core_exchange_rate ); FC_ASSERT((total_fee * fee_asset_obj.options.core_exchange_rate).amount <= - get_object(fee_asset_obj.dynamic_asset_data_id).fee_pool, + get_object(fee_asset_obj.dynamic_asset_data_id).fee_pool, "Cannot pay fees in ${asset}, as this asset's fee pool is insufficiently funded.", ("asset", fee_asset_obj.symbol)); } else { @@ -2529,7 +2537,7 @@ public: if( vbid ) { - result.emplace_back( get_object(*vbid), now ); + result.emplace_back( get_object(*vbid), now ); return result; } @@ -2564,7 +2572,7 @@ public: FC_THROW("Account ${account} has no core Token ${TOKEN} vested and thus its not allowed to withdraw.", ("account", witness_name)("TOKEN", GRAPHENE_SYMBOL)); } - vesting_balance_object vbo = get_object< vesting_balance_object >( *vbid ); + vesting_balance_object vbo = get_object( *vbid ); if(vbo.balance_type == vesting_balance_type::gpos) FC_THROW("Allowed to withdraw only Normal and Son type vest balances with this method"); @@ -2609,7 +2617,7 @@ public: //whether it is a witness or user, keep it in a container and iterate over to process all vesting balances and types if(!vbos.size()) - vbos.emplace_back( get_object(*vbid) ); + vbos.emplace_back( get_object(*vbid) ); for (const vesting_balance_object& vesting_balance_obj: vbos) { if(vesting_balance_obj.balance_type == vesting_balance_type::gpos) @@ -2727,6 +2735,7 @@ public: if (!votes_removed) FC_THROW("Account ${account} is already not voting for son ${son}", ("account", voting_account)("son", son)); } + account_update_operation account_update_op; account_update_op.account = voting_account_object.id; account_update_op.new_options = voting_account_object.options; @@ -3137,14 +3146,13 @@ public: return sign_transaction(trx, broadcast); } - signed_transaction cancel_order(object_id_type order_id, bool broadcast = false) + signed_transaction cancel_order(limit_order_id_type order_id, bool broadcast = false) { try { FC_ASSERT(!is_locked()); - FC_ASSERT(order_id.space() == protocol_ids, "Invalid order ID ${id}", ("id", order_id)); signed_transaction trx; limit_order_cancel_operation op; - op.fee_paying_account = get_object(order_id).seller; + op.fee_paying_account = get_object(order_id).seller; op.order = order_id; trx.operations = {op}; set_operation_fees( trx, _remote_db->get_global_properties().parameters.current_fees); @@ -3460,7 +3468,7 @@ public: std::string player_name; if (round == num_rounds) { - match_object match = get_object(tournament_details.matches[num_matches - 1]); + match_object match = get_object(tournament_details.matches[num_matches - 1]); if (match.get_state() == match_state::match_complete && !match.match_winners.empty()) { @@ -3470,7 +3478,7 @@ public: } else { - match_object match = get_object(tournament_details.matches[match_number]); + match_object match = get_object(tournament_details.matches[match_number]); if (!match.players.empty()) { if (player_in_match < match.players.size()) @@ -3508,7 +3516,7 @@ public: return ss.str(); }; - m["get_order_book"] = [this](variant result, const fc::variants& a) + m["get_order_book"] = [](variant result, const fc::variants&) { auto orders = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); auto bids = orders.bids; @@ -4672,7 +4680,7 @@ asset_bitasset_data_object wallet_api::get_bitasset_data(string asset_name_or_id { auto asset = get_asset(asset_name_or_id); FC_ASSERT(asset.is_market_issued() && asset.bitasset_data_id); - return my->get_object(*asset.bitasset_data_id); + return my->get_object(*asset.bitasset_data_id); } account_id_type wallet_api::get_account_id(string account_name_or_id) const @@ -5494,7 +5502,7 @@ string wallet_api::help()const { std::vector method_names = my->method_documentation.get_method_names(); std::stringstream ss; - for (const std::string method_name : method_names) + for (const std::string& method_name : method_names) { try { @@ -6140,7 +6148,7 @@ blind_confirmation wallet_api::blind_transfer_help( string from_key_or_label, conf_output.decrypted_memo.amount = change; conf_output.decrypted_memo.blinding_factor = change_blind_factor; conf_output.decrypted_memo.commitment = change_out.commitment; - conf_output.decrypted_memo.check = from_secret._hash[0]; + conf_output.decrypted_memo.check = from_secret._hash[0].value(); conf_output.confirmation.one_time_key = one_time_key.get_public_key(); conf_output.confirmation.to = from_key; conf_output.confirmation.encrypted_memo = fc::aes_encrypt( from_secret, fc::raw::pack( conf_output.decrypted_memo ) ); @@ -6158,7 +6166,7 @@ blind_confirmation wallet_api::blind_transfer_help( string from_key_or_label, conf_output.decrypted_memo.amount = amount; conf_output.decrypted_memo.blinding_factor = blind_factor; conf_output.decrypted_memo.commitment = to_out.commitment; - conf_output.decrypted_memo.check = secret._hash[0]; + conf_output.decrypted_memo.check = secret._hash[0].value(); conf_output.confirmation.one_time_key = one_time_key.get_public_key(); conf_output.confirmation.to = to_key; conf_output.confirmation.encrypted_memo = fc::aes_encrypt( secret, fc::raw::pack( conf_output.decrypted_memo ) ); @@ -6246,7 +6254,7 @@ blind_confirmation wallet_api::transfer_to_blind( string from_account_id_or_name conf_output.decrypted_memo.amount = amount; conf_output.decrypted_memo.blinding_factor = blind_factor; conf_output.decrypted_memo.commitment = out.commitment; - conf_output.decrypted_memo.check = secret._hash[0]; + conf_output.decrypted_memo.check = secret._hash[0].value(); conf_output.confirmation.one_time_key = one_time_key.get_public_key(); conf_output.confirmation.to = to_key; conf_output.confirmation.encrypted_memo = fc::aes_encrypt( secret, fc::raw::pack( conf_output.decrypted_memo ) ); @@ -7050,10 +7058,10 @@ signed_transaction wallet_api::rps_throw(game_id_type game_id, FC_ASSERT( !is_locked() ); // check whether the gesture is appropriate for the game we're playing - graphene::chain::game_object game_obj = my->get_object(game_id); - graphene::chain::match_object match_obj = my->get_object(game_obj.match_id); - graphene::chain::tournament_object tournament_obj = my->get_object(match_obj.tournament_id); - graphene::chain::rock_paper_scissors_game_options game_options = + graphene::chain::game_object game_obj = my->get_object(game_id); + graphene::chain::match_object match_obj = my->get_object(game_obj.match_id); + graphene::chain::tournament_object tournament_obj = my->get_object(match_obj.tournament_id); + graphene::chain::rock_paper_scissors_game_options game_options = tournament_obj.options.game_options.get(); if ((int)gesture >= game_options.number_of_gestures) FC_THROW("Gesture ${gesture} not supported in this game", ("gesture", gesture)); @@ -7548,6 +7556,32 @@ vector wallet_api::get_account_roles_by_owner(string owner_ account_object owner_account = my->get_account(owner_account_id_or_name); return my->_remote_db->get_account_roles_by_owner(owner_account.id); } + +signed_transaction wallet_api::run_custom_operation(string payer_id_or_name, std::vector required_auths, string data, uint16_t id, bool broadcast) +{ + account_object payer = my->get_account(payer_id_or_name); + custom_operation op; + + // FC offers no way to have quotes in the data string. Add a simple escape option. + boost::replace_all(data, "\\\"", "\""); + boost::replace_all(data, "\\\\", "\\"); + + op.payer = payer.get_id(); + if (!required_auths.empty()) + std::transform(required_auths.begin(), required_auths.end(), std::inserter(op.required_auths, op.required_auths.begin()), + [&my=my](const string& name_or_id) { return my->get_account(name_or_id).get_id(); }); + op.id = id; + op.data.reserve(data.size()); + op.data.assign(data.begin(), data.end()); + + signed_transaction trx; + trx.operations = {std::move(op)}; + my->set_operation_fees(trx, my->_remote_db->get_global_properties().parameters.current_fees); + trx.validate(); + + return my->sign_transaction(std::move(trx), broadcast); +} + // default ctor necessary for FC_REFLECT signed_block_with_info::signed_block_with_info() { diff --git a/programs/build_helpers/check_reflect.py b/programs/build_helpers/check_reflect.py index 24dc2166..0e78c6b2 100755 --- a/programs/build_helpers/check_reflect.py +++ b/programs/build_helpers/check_reflect.py @@ -108,8 +108,8 @@ def validate_members(name2members_ref, name2members_test): error_items.append(name) print("") print("error in", name) - print("doxygen:", name2members_ref[name]) - print("fc :", name2members_test[name]) + print("doxygen:", sorted(name2members_ref[name])) + print("fc :", sorted(name2members_test[name])) else: ok_items.append(name) return diff --git a/programs/build_helpers/member_enumerator.cpp b/programs/build_helpers/member_enumerator.cpp index d956af38..232d994f 100644 --- a/programs/build_helpers/member_enumerator.cpp +++ b/programs/build_helpers/member_enumerator.cpp @@ -18,8 +18,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -#include -#include +#include +#include #include #include #include @@ -109,7 +109,7 @@ void class_processor::process_class( const static_variant< T... >* dummy ) } } -template +template struct if_enum { template< typename T > @@ -130,7 +130,7 @@ struct if_enum }; template<> -struct if_enum +struct if_enum { template< typename T > static void process_class( class_processor* proc, const T* dummy ) @@ -140,7 +140,7 @@ struct if_enum } }; -template +template struct if_reflected { template< typename T > @@ -152,12 +152,12 @@ struct if_reflected }; template<> -struct if_reflected +struct if_reflected { template< typename T > static void process_class( class_processor* proc, const T* dummy ) { - if_enum< typename fc::reflector::is_enum >::process_class(proc, dummy); + if_enum< std::is_enum::value >::process_class(proc, dummy); } }; @@ -216,7 +216,7 @@ int main( int argc, char** argv ) graphene::member_enumerator::class_processor::process_class(result); fc::mutable_variant_object mvo; - for( const std::pair< std::string, std::vector< std::string > >& e : result ) + for( const auto& e : result ) { variant v; to_variant( e.second, v , 1); diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index 5a0ee3ba..bc8e8b10 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -29,16 +29,13 @@ #include #include -#include #include #include -#include #include -#include #include #include -#include +#include #include #include #include @@ -82,7 +79,8 @@ int main( int argc, char** argv ) ("rpc-endpoint,r", bpo::value()->implicit_value("127.0.0.1:8091"), "Endpoint for wallet websocket RPC to listen on") ("rpc-tls-endpoint,t", bpo::value()->implicit_value("127.0.0.1:8092"), "Endpoint for wallet websocket TLS RPC to listen on") ("rpc-tls-certificate,c", bpo::value()->implicit_value("server.pem"), "PEM certificate for wallet websocket TLS RPC") - ("rpc-http-endpoint,H", bpo::value()->implicit_value("127.0.0.1:8093"), "Endpoint for wallet HTTP RPC to listen on") + ("rpc-http-endpoint,H", bpo::value()->implicit_value("127.0.0.1:8093"), + "Endpoint for wallet HTTP RPC to listen on (DEPRECATED, use rpc-endpoint instead)") ("daemon,d", "Run the wallet in daemon mode" ) ("wallet-file,w", bpo::value()->implicit_value("wallet.json"), "wallet to load") ("chain-id", bpo::value(), "chain ID to connect to"); @@ -235,7 +233,7 @@ int main( int argc, char** argv ) wsc->register_api(wapi); c->set_session_data( wsc ); }); - ilog( "Listening for incoming RPC requests on ${p}", ("p", options.at("rpc-endpoint").as() )); + ilog( "Listening for incoming HTTP and WS RPC requests on ${p}", ("p", options.at("rpc-endpoint").as() )); _websocket_server->listen( fc::ip::endpoint::from_string(options.at("rpc-endpoint").as()) ); _websocket_server->start_accept(); } @@ -244,36 +242,32 @@ int main( int argc, char** argv ) if( options.count( "rpc-tls-certificate" ) ) cert_pem = options.at("rpc-tls-certificate").as(); - std::shared_ptr _websocket_tls_server; + auto _websocket_tls_server = std::make_shared(cert_pem, ""); if( options.count("rpc-tls-endpoint") ) { - _websocket_tls_server = std::make_shared(cert_pem); _websocket_tls_server->on_connection([&]( const fc::http::websocket_connection_ptr& c ){ auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); wsc->register_api(wapi); c->set_session_data( wsc ); }); - ilog( "Listening for incoming TLS RPC requests on ${p}", ("p", options.at("rpc-tls-endpoint").as() )); + ilog( "Listening for incoming HTTPS and WSS RPC requests on ${p}", + ("p", options.at("rpc-tls-endpoint").as()) ); _websocket_tls_server->listen( fc::ip::endpoint::from_string(options.at("rpc-tls-endpoint").as()) ); _websocket_tls_server->start_accept(); } - auto _http_server = std::make_shared(); + auto _http_ws_server = std::make_shared(); if( options.count("rpc-http-endpoint" ) ) { - ilog( "Listening for incoming HTTP RPC requests on ${p}", ("p", options.at("rpc-http-endpoint").as() ) ); - _http_server->listen( fc::ip::endpoint::from_string( options.at( "rpc-http-endpoint" ).as() ) ); - // - // due to implementation, on_request() must come AFTER listen() - // - _http_server->on_request( - [&wapi]( const fc::http::request& req, const fc::http::server::response& resp ) - { - std::shared_ptr< fc::rpc::http_api_connection > conn = - std::make_shared< fc::rpc::http_api_connection >( GRAPHENE_MAX_NESTED_OBJECTS ); - conn->register_api( wapi ); - conn->on_request( req, resp ); - } ); + ilog( "Listening for incoming HTTP and WS RPC requests on ${p}", + ("p", options.at("rpc-http-endpoint").as()) ); + _http_ws_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ + auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); + wsc->register_api(wapi); + c->set_session_data( wsc ); + }); + _http_ws_server->listen( fc::ip::endpoint::from_string(options.at("rpc-http-endpoint").as()) ); + _http_ws_server->start_accept(); } if( !options.count( "daemon" ) ) @@ -284,7 +278,7 @@ int main( int argc, char** argv ) } else { - fc::promise::ptr exit_promise = new fc::promise("UNIX Signal Handler"); + fc::promise::ptr exit_promise = fc::promise::create("UNIX Signal Handler"); fc::set_signal_handler([&exit_promise](int signal) { exit_promise->set_value(signal); }, SIGINT); diff --git a/programs/debug_node/main.cpp b/programs/debug_node/main.cpp index c94d3fd2..c93909b6 100644 --- a/programs/debug_node/main.cpp +++ b/programs/debug_node/main.cpp @@ -164,7 +164,7 @@ int main(int argc, char** argv) { node->startup(); node->startup_plugins(); - fc::promise::ptr exit_promise = new fc::promise("UNIX Signal Handler"); + fc::promise::ptr exit_promise = fc::promise::create("UNIX Signal Handler"); fc::set_signal_handler([&exit_promise](int signal) { elog( "Caught SIGINT attempting to exit cleanly" ); diff --git a/programs/delayed_node/main.cpp b/programs/delayed_node/main.cpp index 3e058b64..c9be9e79 100644 --- a/programs/delayed_node/main.cpp +++ b/programs/delayed_node/main.cpp @@ -179,7 +179,7 @@ int main(int argc, char** argv) { node.startup(); node.startup_plugins(); - fc::promise::ptr exit_promise = new fc::promise("UNIX Signal Handler"); + fc::promise::ptr exit_promise = fc::promise::create("UNIX Signal Handler"); fc::set_signal_handler([&exit_promise](int signal) { exit_promise->set_value(signal); }, SIGINT); diff --git a/programs/genesis_util/convert_address.cpp b/programs/genesis_util/convert_address.cpp index 7f73acdb..f8224cc8 100644 --- a/programs/genesis_util/convert_address.cpp +++ b/programs/genesis_util/convert_address.cpp @@ -26,13 +26,13 @@ * Convert BTC / PTS addresses to a Graphene address. */ -#include -#include +#include +#include #include #include -using namespace graphene::chain; +using namespace graphene::protocol; int main(int argc, char** argv) { diff --git a/programs/genesis_util/genesis_update.cpp b/programs/genesis_util/genesis_update.cpp index 4df7091f..136603a4 100644 --- a/programs/genesis_util/genesis_update.cpp +++ b/programs/genesis_util/genesis_update.cpp @@ -32,8 +32,7 @@ #include #include -#include -#include +#include #include #include diff --git a/programs/genesis_util/get_dev_key.cpp b/programs/genesis_util/get_dev_key.cpp index ea7cdf9f..4fc6a42f 100644 --- a/programs/genesis_util/get_dev_key.cpp +++ b/programs/genesis_util/get_dev_key.cpp @@ -28,8 +28,8 @@ #include #include -#include -#include +#include +#include #include #ifndef WIN32 @@ -73,10 +73,10 @@ int main( int argc, char** argv ) auto show_key = [&comma]( const fc::ecc::private_key& priv_key ) { fc::limited_mutable_variant_object mvo(5); - graphene::chain::public_key_type pub_key = priv_key.get_public_key(); + graphene::protocol::public_key_type pub_key = priv_key.get_public_key(); mvo( "private_key", graphene::utilities::key_to_wif( priv_key ) ) ( "public_key", std::string( pub_key ) ) - ( "address", graphene::chain::address( pub_key ) ) + ( "address", graphene::protocol::address( pub_key ) ) ; if( comma ) std::cout << ",\n"; diff --git a/programs/js_operation_serializer/main.cpp b/programs/js_operation_serializer/main.cpp index 797a32a1..b5b00daa 100644 --- a/programs/js_operation_serializer/main.cpp +++ b/programs/js_operation_serializer/main.cpp @@ -21,8 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include + +#include +#include #include #include @@ -120,12 +121,13 @@ bool register_serializer( const string& name, std::function sr ) template struct js_name { static std::string name(){ return remove_namespace(fc::get_typename::name()); }; }; template -struct js_name> +struct js_name> { - static std::string name(){ return "fixed_array "+ fc::to_string(N) + ", " + remove_namespace(fc::get_typename::name()); }; + static std::string name(){ return "fixed_array "+ fc::to_string(N) + ", " + + remove_namespace(fc::get_typename::name()); }; }; -template struct js_name> { static std::string name(){ return "bytes "+ fc::to_string(N); }; }; -template struct js_name> { static std::string name(){ return "bytes "+ fc::to_string(N); }; }; +template struct js_name> { static std::string name(){ return "bytes "+ fc::to_string(N); }; }; +template struct js_name>{ static std::string name(){ return "bytes "+ fc::to_string(N); }; }; template struct js_name< fc::optional > { static std::string name(){ return "optional " + js_name::name(); } }; template<> struct js_name< object_id_type > { static std::string name(){ return "object_id_type"; } }; template struct js_name< fc::flat_set > { static std::string name(){ return "set " + js_name::name(); } }; @@ -138,15 +140,15 @@ template<> struct js_name { static std::string name(){ retu template<> struct js_name { static std::string name(){ return "bytes 28"; } }; template<> struct js_name { static std::string name(){ return "bytes 32"; } }; template<> struct js_name { static std::string name(){ return "varuint32"; } }; -template<> struct js_name { static std::string name(){ return "varint32"; } }; template<> struct js_name< vote_id_type > { static std::string name(){ return "vote_id"; } }; template<> struct js_name< time_point_sec > { static std::string name(){ return "time_point_sec"; } }; -template -struct js_name > +template +struct js_name > { static std::string name(){ - return "protocol_id_type \"" + remove_namespace(fc::get_typename::name()) + "\""; + return "protocol_id_type(\"" + + remove_namespace(fc::get_typename>>::name()) + "\")"; }; }; @@ -242,7 +244,7 @@ struct serializer }; template -struct serializer,false> +struct serializer,false> { static void init() { serializer::init(); } static void generate() {} @@ -289,8 +291,8 @@ struct serializer,false> static void generate(){} }; -template -struct serializer< graphene::db::object_id ,true> +template +struct serializer< graphene::db::object_id ,true> { static void init() {} static void generate() {} @@ -351,14 +353,15 @@ class register_member_visitor } }; -template +template ()> struct serializer_init_helper { static void init() { auto name = js_name::name(); if( st.find(name) == st.end() ) { - fc::reflector::visit( register_member_visitor() ); + register_member_visitor visitor; + fc::reflector::visit( visitor ); register_serializer( name, [=](){ generate(); } ); } } @@ -370,14 +373,15 @@ struct serializer_init_helper { << " = new Serializer( \n" << " \"" + name + "\"\n"; - fc::reflector::visit( serialize_member_visitor() ); + serialize_member_visitor visitor; + fc::reflector::visit( visitor ); std::cout <<")\n\n"; } }; template -struct serializer_init_helper { +struct serializer_init_helper { static void init() { } @@ -390,7 +394,7 @@ struct serializer static void init() { - serializer_init_helper< T, typename fc::reflector::is_enum >::init(); + serializer_init_helper< T >::init(); } }; diff --git a/programs/size_checker/main.cpp b/programs/size_checker/main.cpp index 188e88e4..a7c09308 100644 --- a/programs/size_checker/main.cpp +++ b/programs/size_checker/main.cpp @@ -23,10 +23,12 @@ */ #include +#include #include #include -#include +#include +#include #include #include @@ -34,7 +36,7 @@ #include #include -using namespace graphene::chain; +using namespace graphene::protocol; vector< fc::variant_object > g_op_types; @@ -67,7 +69,7 @@ int main( int argc, char** argv ) { try { - graphene::chain::operation op; + graphene::protocol::operation op; vector witnesses; witnesses.resize(50); diff --git a/programs/witness_node/CMakeLists.txt b/programs/witness_node/CMakeLists.txt index 806330d6..121d8473 100644 --- a/programs/witness_node/CMakeLists.txt +++ b/programs/witness_node/CMakeLists.txt @@ -11,7 +11,7 @@ endif() # We have to link against graphene_debug_witness because deficiency in our API infrastructure doesn't allow plugins to be fully abstracted #246 target_link_libraries( witness_node - PRIVATE graphene_app graphene_egenesis_full graphene_snapshot graphene_witness peerplays_sidechain ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_account_history graphene_affiliate_stats graphene_elasticsearch graphene_market_history graphene_witness graphene_protocol graphene_chain graphene_debug_witness graphene_bookie graphene_egenesis_full graphene_snapshot graphene_es_objects fc peerplays_sidechain ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) # also add dependencies to graphene_generate_genesis graphene_generate_uia_sharedrop_genesis if you want those plugins install( TARGETS diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index af5086b2..fa3176f3 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -162,7 +162,7 @@ int main(int argc, char** argv) { node->startup(); node->startup_plugins(); - fc::promise::ptr exit_promise = new fc::promise("UNIX Signal Handler"); + fc::promise::ptr exit_promise = fc::promise::create("UNIX Signal Handler"); fc::set_signal_handler([&exit_promise](int signal) { elog( "Caught SIGINT attempting to exit cleanly" ); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6ff915a9..bbb74329 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,8 +10,8 @@ target_link_libraries( graphene_tests_common PUBLIC graphene_app graphene_egenesis_none ) file(GLOB UNIT_TESTS "tests/*.cpp") -add_executable( chain_test ${UNIT_TESTS} ) -target_link_libraries( chain_test PRIVATE graphene_wallet graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} ) +target_link_libraries( chain_test graphene_protocol graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_bookie graphene_egenesis_none fc graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( tests/serialization_tests.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) @@ -33,12 +33,12 @@ add_executable( intense_test ${INTENSE_SOURCES} ) target_link_libraries( intense_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB BETTING_TESTS "betting/*.cpp") -add_executable( betting_test ${BETTING_TESTS} ) -target_link_libraries( betting_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( betting_test ${BETTING_TESTS} ${COMMON_SOURCES} ) +target_link_libraries( betting_test graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_bookie graphene_egenesis_none fc graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB PEERPLAYS_SIDECHAIN_TESTS "peerplays_sidechain/*.cpp") -add_executable( peerplays_sidechain_test ${PEERPLAYS_SIDECHAIN_TESTS} ) -target_link_libraries( peerplays_sidechain_test PRIVATE graphene_tests_common peerplays_sidechain ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( peerplays_sidechain_test ${PEERPLAYS_SIDECHAIN_TESTS} ${COMMON_SOURCES} ) +target_link_libraries( peerplays_sidechain_test graphene_chain graphene_app graphene_account_history graphene_bookie graphene_elasticsearch graphene_es_objects graphene_egenesis_none fc graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB TOURNAMENT_TESTS "tournament/*.cpp") add_executable( tournament_test ${TOURNAMENT_TESTS} ) @@ -53,7 +53,7 @@ add_executable( cli_test ${CLI_SOURCES} ) if(WIN32) list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32) endif() -target_link_libraries( cli_test PRIVATE graphene_wallet graphene_tests_common graphene_witness ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( cli_test graphene_chain graphene_app graphene_witness graphene_wallet graphene_egenesis_none fc graphene_elasticsearch graphene_es_objects ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( cli/main.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) diff --git a/tests/benchmarks/main.cpp b/tests/benchmarks/main.cpp index 706318d6..479fb337 100644 --- a/tests/benchmarks/main.cpp +++ b/tests/benchmarks/main.cpp @@ -23,3 +23,4 @@ */ #define BOOST_TEST_MODULE "C++ Benchmarks for Graphene Blockchain Database" #include + diff --git a/tests/betting/betting_tests.cpp b/tests/betting/betting_tests.cpp index 3898bb6c..bf111f8a 100644 --- a/tests/betting/betting_tests.cpp +++ b/tests/betting/betting_tests.cpp @@ -21,6 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#define BOOST_TEST_MODULE Peerplays Betting Tests + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // disable auto_ptr deprecated warning, see https://svn.boost.org/trac10/ticket/11622 @@ -35,7 +38,7 @@ #include #include -#include +#include #include #include @@ -2403,6 +2406,7 @@ BOOST_AUTO_TEST_CASE(event_driven_progression_errors_2) // as soon as a block is generated, the betting market group will settle, and the market // and group will cease to exist. The event should transition to "settled", then removed fc::variants objects_from_bookie = bookie_api.get_objects({capitals_vs_blackhawks_id}); + wdump((objects_from_bookie)(capitals_vs_blackhawks_id(db))); BOOST_CHECK_EQUAL(objects_from_bookie[0]["status"].as(1), "settled"); // we can't go back to upcoming, in_progress, frozen, or finished once we're canceled. @@ -2855,21 +2859,20 @@ BOOST_AUTO_TEST_CASE( wimbledon_2017_gentelmen_singles_final_test ) BOOST_AUTO_TEST_SUITE_END() +struct GlobalInitializationFixture { + GlobalInitializationFixture() { + std::srand(time(NULL)); + std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - -//#define BOOST_TEST_MODULE "C++ Unit Tests for Graphene Blockchain Database" -#include -#include -#include - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - - // betting operations don't take effect until HARDFORK 1000 - GRAPHENE_TESTING_GENESIS_TIMESTAMP = - (HARDFORK_1000_TIME.sec_since_epoch() + 15) / GRAPHENE_DEFAULT_BLOCK_INTERVAL * GRAPHENE_DEFAULT_BLOCK_INTERVAL; - - return nullptr; -} + // The genesis timestamp (GRAPHENE_TESTING_GENESIS_TIMESTAMP), + // which is verified by database::init_genesis(), + // should maintain compatibility with the periodicity + // expected from the GRAPHENE_DEFAULT_BLOCK_INTERVAL. + // + // betting operations don't take effect until HARDFORK 1000 + GRAPHENE_TESTING_GENESIS_TIMESTAMP = + (HARDFORK_1000_TIME.sec_since_epoch() + 15) / GRAPHENE_DEFAULT_BLOCK_INTERVAL * GRAPHENE_DEFAULT_BLOCK_INTERVAL; + } +}; +BOOST_TEST_GLOBAL_FIXTURE(GlobalInitializationFixture); diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 49bfa387..5ff95c69 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -502,3 +502,4 @@ BOOST_FIXTURE_TEST_CASE( saving_keys_wallet_test, cli_fixture ) } BOOST_AUTO_TEST_SUITE_END() + diff --git a/tests/common/betting_test_markets.hpp b/tests/common/betting_test_markets.hpp index e774267b..0cb5cae4 100644 --- a/tests/common/betting_test_markets.hpp +++ b/tests/common/betting_test_markets.hpp @@ -30,6 +30,8 @@ using namespace graphene::chain; +template object_id to_id(const O& o) { return o.id; } + #define CREATE_ICE_HOCKEY_BETTING_MARKET(never_in_play, delay_before_settling) \ create_sport({{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); \ generate_blocks(1); \ @@ -149,6 +151,8 @@ struct simple_bet_test_fixture : database_fixture { { ACTORS( (alice)(bob) ); CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); + capitals_win_betting_market_id = capitals_win_market_id; + blackhawks_win_betting_market_id = blackhawks_win_market_id; // give alice and bob 10k each transfer(account_id_type(), alice_id, asset(10000)); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index a88f0804..bba6240f 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -709,7 +709,7 @@ void database_fixture::issue_uia( account_id_type recipient_id, asset amount ) } void database_fixture::change_fees( - const flat_set< fee_parameters >& new_params, + const fee_parameters::flat_set_type& new_params, uint32_t new_scale /* = 0 */ ) { @@ -1632,6 +1632,7 @@ void database_fixture::resolve_betting_market_group(betting_market_group_id_type betting_market_group_resolve_operation betting_market_group_resolve_op; betting_market_group_resolve_op.betting_market_group_id = betting_market_group_id; betting_market_group_resolve_op.resolutions = resolutions; + wdump((resolutions)(betting_market_group_resolve_op)); process_operation_by_witnesses(betting_market_group_resolve_op); } FC_CAPTURE_AND_RETHROW( (betting_market_group_id)(resolutions) ) } diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index cd6ac185..91969d83 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -23,11 +23,21 @@ */ #pragma once -#include -#include #include +#include +#include + +#include +#include #include +#include +#include +#include + +#include +#include +#include #include @@ -289,7 +299,7 @@ struct database_fixture { void transfer( const account_object& from, const account_object& to, const asset& amount, const asset& fee = asset() ); void fund_fee_pool( const account_object& from, const asset_object& asset_to_fund, const share_type amount ); void enable_fees(); - void change_fees( const flat_set< fee_parameters >& new_params, uint32_t new_scale = 0 ); + void change_fees( const fee_parameters::flat_set_type& new_params, uint32_t new_scale = 0 ); void upgrade_to_lifetime_member( account_id_type account ); void upgrade_to_lifetime_member( const account_object& account ); void upgrade_to_annual_member( account_id_type account ); diff --git a/tests/generate_empty_blocks/main.cpp b/tests/generate_empty_blocks/main.cpp index 298b03cd..b3da426d 100644 --- a/tests/generate_empty_blocks/main.cpp +++ b/tests/generate_empty_blocks/main.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -132,14 +132,14 @@ int main( int argc, char** argv ) signed_block b = db.generate_block(db.get_slot_time(slot), db.get_scheduled_witness(slot), nathan_priv_key, database::skip_nothing); FC_ASSERT( db.head_block_id() == b.id() ); fc::sha256 h = b.digest(); - uint64_t rand = h._hash[0]; + uint64_t rand = h._hash[0].value(); slot = 1; while(true) { if( (rand % 100) < miss_rate ) { slot++; - rand = (rand/100) ^ h._hash[slot&3]; + rand = (rand/100) ^ h._hash[slot&3].value(); missed++; } else diff --git a/tests/intense/block_tests.cpp b/tests/intense/block_tests.cpp index 7004f13f..25134fce 100644 --- a/tests/intense/block_tests.cpp +++ b/tests/intense/block_tests.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/intense/main.cpp b/tests/intense/main.cpp index c337407f..5e9a5fd2 100644 --- a/tests/intense/main.cpp +++ b/tests/intense/main.cpp @@ -21,12 +21,19 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#define BOOST_TEST_MODULE Intense Tests + +#include + #include #include -#include -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - return nullptr; -} +struct GlobalInitializationFixture { + GlobalInitializationFixture() { + std::srand(time(NULL)); + std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + } +}; +BOOST_TEST_GLOBAL_FIXTURE(GlobalInitializationFixture); + diff --git a/tests/peerplays_sidechain/bitcoin_address_tests.cpp b/tests/peerplays_sidechain/bitcoin_address_tests.cpp index a6909e24..405d848b 100644 --- a/tests/peerplays_sidechain/bitcoin_address_tests.cpp +++ b/tests/peerplays_sidechain/bitcoin_address_tests.cpp @@ -1,6 +1,7 @@ #include #include +using namespace graphene::protocol; using namespace graphene::peerplays_sidechain::bitcoin; BOOST_AUTO_TEST_SUITE(bitcoin_address_tests) diff --git a/tests/peerplays_sidechain/bitcoin_sign_tests.cpp b/tests/peerplays_sidechain/bitcoin_sign_tests.cpp index 82a121c9..87244fd5 100644 --- a/tests/peerplays_sidechain/bitcoin_sign_tests.cpp +++ b/tests/peerplays_sidechain/bitcoin_sign_tests.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -192,7 +193,8 @@ BOOST_AUTO_TEST_CASE(weighted_multisig_spend_test) { int32_t hash_type = 1; // implement SIGHASH_ALL scheme for (auto &key : priv_keys) { - bytes key_data(key.get_secret().data(), key.get_secret().data() + key.get_secret().data_size()); + auto secret = key.get_secret(); + bytes key_data(secret.data(), secret.data() + secret.data_size()); std::vector sigs = sign_witness_transaction_part(tx, {redeem_script}, {amount}, key_data, btc_context(), hash_type); // insert signatures in reverse order tx.vin[0].scriptWitness.insert(tx.vin[0].scriptWitness.begin(), sigs[0]); @@ -334,7 +336,8 @@ BOOST_AUTO_TEST_CASE(user_sig_one_or_weighted_multisig_spend_test) { uint64_t amount = 10000; int32_t hash_type = 1; // implement SIGHASH_ALL scheme - bytes key_data(user_key.get_secret().data(), user_key.get_secret().data() + user_key.get_secret().data_size()); + auto secret = user_key.get_secret(); + bytes key_data(secret.data(), secret.data() + secret.data_size()); std::vector sigs = sign_witness_transaction_part(tx, {redeem_script}, {amount}, key_data, btc_context(), hash_type); tx.vin[0].scriptWitness.push_back(sigs[0]); sign_witness_transaction_finalize(tx, {redeem_script}, false); @@ -368,7 +371,8 @@ BOOST_AUTO_TEST_CASE(user_sig_one_or_weighted_multisig_spend_test) { int32_t hash_type = 1; // implement SIGHASH_ALL scheme for (auto &key : priv_keys) { - bytes key_data(key.get_secret().data(), key.get_secret().data() + key.get_secret().data_size()); + auto secret = key.get_secret(); + bytes key_data(secret.data(), secret.data() + secret.data_size()); std::vector sigs = sign_witness_transaction_part(tx, {redeem_script}, {amount}, key_data, btc_context(), hash_type); // insert signatures in reverse order tx.vin[0].scriptWitness.insert(tx.vin[0].scriptWitness.begin(), sigs[0]); @@ -434,7 +438,8 @@ BOOST_AUTO_TEST_CASE(user_sig_timelocked_one_or_weighted_multisig_spend_test) { uint64_t amount = 10000; int32_t hash_type = 1; // implement SIGHASH_ALL scheme - bytes key_data(user_key.get_secret().data(), user_key.get_secret().data() + user_key.get_secret().data_size()); + auto secret = user_key.get_secret(); + bytes key_data(secret.data(), secret.data() + secret.data_size()); std::vector sigs = sign_witness_transaction_part(tx, {redeem_script}, {amount}, key_data, btc_context(), hash_type); tx.vin[0].scriptWitness.push_back(sigs[0]); sign_witness_transaction_finalize(tx, {redeem_script}, false); diff --git a/tests/peerplays_sidechain/peerplays_sidechain_tests.cpp b/tests/peerplays_sidechain/peerplays_sidechain_tests.cpp index 84577384..7a7f9f9a 100644 --- a/tests/peerplays_sidechain/peerplays_sidechain_tests.cpp +++ b/tests/peerplays_sidechain/peerplays_sidechain_tests.cpp @@ -1,17 +1,17 @@ +#define BOOST_TEST_MODULE Peerplays SON Tests + #include -#define BOOST_TEST_MODULE Peerplays SON Tests +#include BOOST_AUTO_TEST_CASE(peerplays_sidechain) { } -#include -#include -#include +struct GlobalInitializationFixture { + GlobalInitializationFixture() { + std::srand(time(NULL)); + std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + } +}; +BOOST_TEST_GLOBAL_FIXTURE(GlobalInitializationFixture); -boost::unit_test::test_suite *init_unit_test_suite(int argc, char *argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - - return nullptr; -} diff --git a/tests/performance/performance_tests.cpp b/tests/performance/performance_tests.cpp index e7d0c98b..c3fc2d74 100644 --- a/tests/performance/performance_tests.cpp +++ b/tests/performance/performance_tests.cpp @@ -21,10 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#define BOOST_TEST_MODULE Performance Tests + #include #include -#include +#include #include #include @@ -71,13 +74,11 @@ BOOST_AUTO_TEST_CASE( transfer_benchmark ) //BOOST_AUTO_TEST_SUITE_END() -//#define BOOST_TEST_MODULE "C++ Unit Tests for Graphene Blockchain Database" -#include -#include -#include +struct GlobalInitializationFixture { + GlobalInitializationFixture() { + std::srand(time(NULL)); + std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + } +}; +BOOST_TEST_GLOBAL_FIXTURE(GlobalInitializationFixture); -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - return nullptr; -} diff --git a/tests/random/random_tests.cpp b/tests/random/random_tests.cpp index e224439a..10c19d75 100644 --- a/tests/random/random_tests.cpp +++ b/tests/random/random_tests.cpp @@ -21,6 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#define BOOST_TEST_MODULE Random Tests + #include //#include //#include @@ -131,24 +134,24 @@ BOOST_FIXTURE_TEST_CASE( basic, database_fixture ) BOOST_AUTO_TEST_SUITE_END() -//#define BOOST_TEST_MODULE "C++ Unit Tests for Graphene Blockchain Database" -#include -#include -#include - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - for (int i=1; i #include -#include +#include #include #include -#include +#include #include #include @@ -16,6 +16,9 @@ #include #include +#include +#include + #include #include @@ -376,4 +379,4 @@ BOOST_AUTO_TEST_CASE(nft_offer_bid_account_role_test) FC_LOG_AND_RETHROW() } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/authority_tests.cpp b/tests/tests/authority_tests.cpp index 387036df..f298d758 100644 --- a/tests/tests/authority_tests.cpp +++ b/tests/tests/authority_tests.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/tests/tests/basic_tests.cpp b/tests/tests/basic_tests.cpp index 5b4c98cb..32e539fd 100644 --- a/tests/tests/basic_tests.cpp +++ b/tests/tests/basic_tests.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 7571feb6..6bd10d7d 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -1031,9 +1031,9 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, database_fixture ) { generate_block(); - auto rsf = [&]() -> string + auto rsf = [this]() -> string { - fc::uint128 rsf; + fc::uint128_t rsf; if (db.get_global_properties().parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SCHEDULED_ALGORITHM) rsf = db.get(witness_schedule_id_type()).recent_slots_filled; else @@ -1042,7 +1042,7 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, database_fixture ) result.reserve(128); for( int i=0; i<128; i++ ) { - result += ((rsf.lo & 1) == 0) ? '0' : '1'; + result += rsf & 1 ? '1' : '0'; rsf >>= 1; } return result; diff --git a/tests/tests/confidential_tests.cpp b/tests/tests/confidential_tests.cpp index 792a300e..acb50e8a 100644 --- a/tests/tests/confidential_tests.cpp +++ b/tests/tests/confidential_tests.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/tests/tests/custom_permission_tests.cpp b/tests/tests/custom_permission_tests.cpp index 4aad1897..b8a111f6 100644 --- a/tests/tests/custom_permission_tests.cpp +++ b/tests/tests/custom_permission_tests.cpp @@ -1,7 +1,6 @@ -#include #include #include -#include +#include #include #include @@ -13,7 +12,12 @@ #include +#include + #include + +#include + #include "../common/database_fixture.hpp" using namespace graphene::chain; diff --git a/tests/tests/database_tests.cpp b/tests/tests/database_tests.cpp index e0644b1b..e3971e42 100644 --- a/tests/tests/database_tests.cpp +++ b/tests/tests/database_tests.cpp @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE( flat_index_test ) price_feed current_feed; current_feed.settlement_price = bitusd.amount(100) / asset(100); publish_feed(bitusd, sam, current_feed); - FC_ASSERT( bitusd.bitasset_data_id->instance == 0 ); + FC_ASSERT( bitusd.bitasset_data_id->instance.value == 0 ); FC_ASSERT( !(*bitusd.bitasset_data_id)(db).current_feed.settlement_price.is_null() ); try { auto ses = db._undo_db.start_undo_session(); diff --git a/tests/tests/fee_tests.cpp b/tests/tests/fee_tests.cpp index 86dd3d7f..17607f6f 100644 --- a/tests/tests/fee_tests.cpp +++ b/tests/tests/fee_tests.cpp @@ -34,6 +34,8 @@ #include #include +#include + #include #include "../common/database_fixture.hpp" @@ -244,7 +246,7 @@ uint64_t pct( uint64_t percentage, uint64_t val ) fc::uint128_t x = percentage; x *= val; x /= GRAPHENE_100_PERCENT; - return x.to_uint64(); + return static_cast(x); } uint64_t pct( uint64_t percentage0, uint64_t percentage1, uint64_t val ) diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp index f716281e..96d69d4a 100644 --- a/tests/tests/gpos_tests.cpp +++ b/tests/tests/gpos_tests.cpp @@ -648,7 +648,7 @@ BOOST_AUTO_TEST_CASE( voting ) // default gpos values BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period(), 15552000); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), 2592000); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), HARDFORK_GPOS_TIME.sec_since_epoch()); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), GPOS_PERIOD_START.sec_since_epoch()); // update default gpos for test speed // 5184000 = 60x60x24x60 = 60 days diff --git a/tests/tests/main.cpp b/tests/tests/main.cpp index 405e7c10..deb48143 100644 --- a/tests/tests/main.cpp +++ b/tests/tests/main.cpp @@ -21,20 +21,20 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#define BOOST_TEST_MODULE Tests + #include #include #include extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); - if( genesis_timestamp_str != nullptr ) - { - GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); - } - std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; - return nullptr; -} +struct GlobalInitializationFixture { + GlobalInitializationFixture() { + std::srand(time(NULL)); + std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + } +}; +BOOST_TEST_GLOBAL_FIXTURE(GlobalInitializationFixture); + diff --git a/tests/tests/network_broadcast_api_tests.cpp b/tests/tests/network_broadcast_api_tests.cpp index aefb7534..3038e547 100644 --- a/tests/tests/network_broadcast_api_tests.cpp +++ b/tests/tests/network_broadcast_api_tests.cpp @@ -5,10 +5,11 @@ #include #include #include -#include +#include #include #include -#include +#include +#include #include #include diff --git a/tests/tests/serialization_tests.cpp b/tests/tests/serialization_tests.cpp index 59e16f01..91085af4 100644 --- a/tests/tests/serialization_tests.cpp +++ b/tests/tests/serialization_tests.cpp @@ -86,42 +86,6 @@ BOOST_AUTO_TEST_CASE( json_tests ) } } -BOOST_AUTO_TEST_CASE( extended_private_key_type_test ) -{ - try - { - fc::ecc::extended_private_key key = fc::ecc::extended_private_key( fc::ecc::private_key::generate(), - fc::sha256(), - 0, 0, 0 ); - extended_private_key_type type = extended_private_key_type( key ); - std::string packed = std::string( type ); - extended_private_key_type unpacked = extended_private_key_type( packed ); - BOOST_CHECK( type == unpacked ); - } catch ( const fc::exception& e ) - { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( extended_public_key_type_test ) -{ - try - { - fc::ecc::extended_public_key key = fc::ecc::extended_public_key( fc::ecc::private_key::generate().get_public_key(), - fc::sha256(), - 0, 0, 0 ); - extended_public_key_type type = extended_public_key_type( key ); - std::string packed = std::string( type ); - extended_public_key_type unpacked = extended_public_key_type( packed ); - BOOST_CHECK( type == unpacked ); - } catch ( const fc::exception& e ) - { - edump((e.to_detail_string())); - throw; - } -} - BOOST_AUTO_TEST_CASE( extension_serialization_test ) { try diff --git a/tests/tests/sidechain_addresses_test.cpp b/tests/tests/sidechain_addresses_test.cpp index 755ad37f..99d28d4b 100644 --- a/tests/tests/sidechain_addresses_test.cpp +++ b/tests/tests/sidechain_addresses_test.cpp @@ -5,7 +5,8 @@ #include #include #include -#include + +#include using namespace graphene::chain; using namespace graphene::chain::test; diff --git a/tests/tests/son_wallet_tests.cpp b/tests/tests/son_wallet_tests.cpp index cef29b54..dcde84c8 100644 --- a/tests/tests/son_wallet_tests.cpp +++ b/tests/tests/son_wallet_tests.cpp @@ -4,7 +4,8 @@ #include #include -#include + +#include using namespace graphene; using namespace graphene::chain; diff --git a/tests/tournament/tournament_tests.cpp b/tests/tournament/tournament_tests.cpp index 0593fd79..a2167bfd 100644 --- a/tests/tournament/tournament_tests.cpp +++ b/tests/tournament/tournament_tests.cpp @@ -21,6 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#define BOOST_TEST_MODULE Peerplays Tournament Tests + #include #include #include @@ -273,7 +276,6 @@ BOOST_FIXTURE_TEST_CASE( whitelist_must_not_be_longer_than, database_fixture ) BOOST_CHECK(nathan.is_lifetime_member()); asset buy_in = asset(10000); - db.get_global_properties().parameters.maximum_tournament_whitelist_length; flat_set whitelist; for(uint16_t i = 0; i < db.get_global_properties().parameters.maximum_tournament_whitelist_length+1; ++i) { @@ -1611,7 +1613,7 @@ BOOST_FIXTURE_TEST_CASE( simple, database_fixture ) const account_object winner = winner_id(db); BOOST_TEST_MESSAGE( "The winner is " + winner.name ); - share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); + share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100); optional dividend_account = tournament_helper.get_asset_dividend_account(tournament.options.buy_in.asset_id); if (dividend_account.valid()) players_balances[*dividend_account][tournament.options.buy_in.asset_id] += rake_amount; @@ -1728,7 +1730,7 @@ BOOST_FIXTURE_TEST_CASE( ties, database_fixture ) assert(final_match.match_winners.size() == 1); const account_id_type& winner_id = *final_match.match_winners.begin(); BOOST_TEST_MESSAGE( "The winner of " + std::string(object_id_type(tournament_id)) + " is " + winner_id(db).name + " " + std::string(object_id_type(winner_id))); - share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); + share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100); optional dividend_account = tournament_helper.get_asset_dividend_account(tournament.options.buy_in.asset_id); if (dividend_account.valid()) players_balances[*dividend_account][tournament.options.buy_in.asset_id] += rake_amount; @@ -1941,7 +1943,7 @@ BOOST_FIXTURE_TEST_CASE( assets, database_fixture ) assert(final_match.match_winners.size() == 1); const account_id_type& winner_id = *final_match.match_winners.begin(); BOOST_TEST_MESSAGE( "The winner of " + std::string(object_id_type(tournament_id)) + " is " + winner_id(db).name + " " + std::string(object_id_type(winner_id))); - share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); + share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100); optional dividend_account = tournament_helper.get_asset_dividend_account(tournament.options.buy_in.asset_id); if (dividend_account.valid()) players_balances[*dividend_account][tournament.options.buy_in.asset_id] += rake_amount; @@ -2078,7 +2080,7 @@ BOOST_FIXTURE_TEST_CASE( basic, database_fixture ) assert(final_match.match_winners.size() == 1); const account_id_type& winner_id = *final_match.match_winners.begin(); BOOST_TEST_MESSAGE( "The winner of " + std::string(object_id_type(tournament_id)) + " is " + winner_id(db).name + " " + std::string(object_id_type(winner_id))); - share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); + share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100); optional dividend_account = tournament_helper.get_asset_dividend_account(tournament.options.buy_in.asset_id); if (dividend_account.valid()) players_initial_balances[*dividend_account][tournament.options.buy_in.asset_id] += rake_amount; @@ -2216,7 +2218,7 @@ BOOST_FIXTURE_TEST_CASE( massive, database_fixture ) assert(final_match.match_winners.size() == 1); const account_id_type& winner_id = *final_match.match_winners.begin(); BOOST_TEST_MESSAGE( "The winner of " + std::string(object_id_type(tournament_id)) + " is " + winner_id(db).name + " " + std::string(object_id_type(winner_id))); - share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); + share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100); optional dividend_account = tournament_helper.get_asset_dividend_account(tournament.options.buy_in.asset_id); if (dividend_account.valid()) players_balances[*dividend_account][tournament.options.buy_in.asset_id] += rake_amount; @@ -2259,13 +2261,11 @@ BOOST_FIXTURE_TEST_CASE( massive, database_fixture ) BOOST_AUTO_TEST_SUITE_END() -//#define BOOST_TEST_MODULE "C++ Unit Tests for Graphene Blockchain Database" -#include -#include -#include +struct GlobalInitializationFixture { + GlobalInitializationFixture() { + std::srand(time(NULL)); + std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + } +}; +BOOST_TEST_GLOBAL_FIXTURE(GlobalInitializationFixture); -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - return nullptr; -}