diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c6be0bc..65541631 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ -# Defines BitShares library target. -project( BitShares ) +# Defines Peerplays library target. +project( Peerplays ) cmake_minimum_required( VERSION 2.8.12 ) -set( BLOCKCHAIN_NAME "BitShares" ) +set( BLOCKCHAIN_NAME "Peerplays" ) set( CLI_CLIENT_EXECUTABLE_NAME graphene_client ) -set( GUI_CLIENT_EXECUTABLE_NAME BitShares ) +set( GUI_CLIENT_EXECUTABLE_NAME Peerplays ) set( CUSTOM_URL_SCHEME "gcs" ) set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" ) @@ -22,6 +22,34 @@ endif() list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" ) +# function to help with cUrl +macro(FIND_CURL) + if (NOT WIN32 AND NOT APPLE AND CURL_STATICLIB) + find_package(OpenSSL REQUIRED) + set (OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set (CMAKE_FIND_LIBRARY_SUFFIXES .a) + find_package(CURL REQUIRED) + list(APPEND CURL_LIBRARIES ${OPENSSL_LIBRARIES} ${BOOST_THREAD_LIBRARY} ${CMAKE_DL_LIBS}) + set (CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) + else (NOT WIN32 AND NOT APPLE AND CURL_STATICLIB) + find_package(CURL REQUIRED) + endif (NOT WIN32 AND NOT APPLE AND CURL_STATICLIB) + + if( WIN32 ) + if ( MSVC ) + list( APPEND CURL_LIBRARIES Wldap32 ) + endif( MSVC ) + + if( MINGW ) + # MinGW requires a specific order of included libraries ( CURL before ZLib ) + find_package( ZLIB REQUIRED ) + list( APPEND CURL_LIBRARIES ${ZLIB_LIBRARY} pthread ) + endif( MINGW ) + + list( APPEND CURL_LIBRARIES ${PLATFORM_SPECIFIC_LIBS} ) + endif( WIN32 ) +endmacro() + set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") set(GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR}/genesis.json" CACHE PATH "location of the genesis.json to embed in the executable" ) @@ -71,7 +99,7 @@ ENDIF() if( WIN32 ) - message( STATUS "Configuring BitShares on WIN32") + message( STATUS "Configuring Peerplays on WIN32") set( DB_VERSION 60 ) set( BDB_STATIC_LIBS 1 ) @@ -103,20 +131,13 @@ if( WIN32 ) SET(TCL_LIBRARY ${TCL_LIBS}) else( WIN32 ) # Apple AND Linux - - find_library(READLINE_LIBRARIES NAMES readline) - find_path(READLINE_INCLUDE_DIR readline/readline.h) - #if(NOT READLINE_INCLUDE_DIR OR NOT READLINE_LIBRARIES) - # MESSAGE(FATAL_ERROR "Could not find lib readline.") - #endif() - if( APPLE ) # Apple Specific Options Here - message( STATUS "Configuring BitShares on OS X" ) + message( STATUS "Configuring Peerplays on OS X" ) set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall" ) else( APPLE ) # Linux Specific Options Here - message( STATUS "Configuring BitShares on Linux" ) + message( STATUS "Configuring Peerplays on Linux" ) set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -Wall" ) set( rt_library rt ) #set( pthread_library pthread) @@ -135,7 +156,7 @@ else( WIN32 ) # Apple AND Linux endif( APPLE ) if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp -Wno-parentheses -Wno-terminate -Wno-invalid-offsetof -Wno-sign-compare" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" ) if( CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.0.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0.0 ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization" ) @@ -154,7 +175,7 @@ else( WIN32 ) # Apple AND Linux endif( WIN32 ) -set(ENABLE_COVERAGE_TESTING FALSE CACHE BOOL "Build BitShares for code coverage analysis") +set(ENABLE_COVERAGE_TESTING FALSE CACHE BOOL "Build Peerplays for code coverage analysis") if(ENABLE_COVERAGE_TESTING) SET(CMAKE_CXX_FLAGS "--coverage ${CMAKE_CXX_FLAGS}") @@ -163,13 +184,13 @@ endif() add_subdirectory( libraries ) -set(BUILD_BITSHARES_PROGRAMS TRUE CACHE BOOL "Build bitshares executables (witness node, cli wallet, etc)") +set(BUILD_PEERPLAYS_PROGRAMS TRUE CACHE BOOL "Build peerplays executables (witness node, cli wallet, etc)") add_subdirectory( programs ) -set(BUILD_BITSHARES_TESTS TRUE CACHE BOOL "Build bitshares unit tests") -if( BUILD_BITSHARES_TESTS ) +set(BUILD_PEERPLAYS_TESTS TRUE CACHE BOOL "Build peerplays unit tests") +if( BUILD_PEERPLAYS_TESTS ) add_subdirectory( tests ) -endif( BUILD_BITSHARES_TESTS ) +endif( BUILD_PEERPLAYS_TESTS ) if (ENABLE_INSTALLER) @@ -191,18 +212,18 @@ set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}") set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") -set(CPACK_PACKAGE_DESCRIPTION "A client for the BitShares network") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A client for the BitShares network") +set(CPACK_PACKAGE_DESCRIPTION "A client for the Peerplays network") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A client for the Peerplays network") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md") -set(CPACK_PACKAGE_INSTALL_DIRECTORY "BitShares ${CPACK_PACKAGE_VERSION}") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "Peerplays ${CPACK_PACKAGE_VERSION}") if(WIN32) SET(CPACK_GENERATOR "ZIP;NSIS") - set(CPACK_PACKAGE_NAME "BitShares") # override above + set(CPACK_PACKAGE_NAME "Peerplays") # override above set(CPACK_NSIS_EXECUTABLES_DIRECTORY .) - set(CPACK_NSIS_PACKAGE_NAME "BitShares v${CPACK_PACKAGE_VERSION}") + set(CPACK_NSIS_PACKAGE_NAME "Peerplays v${CPACK_PACKAGE_VERSION}") set(CPACK_NSIS_DISPLAY_NAME "${CPACK_NSIS_PACKAGE_NAME}") - set(CPACK_NSIS_DEFINES " !define MUI_STARTMENUPAGE_DEFAULTFOLDER \\\"BitShares\\\"") + set(CPACK_NSIS_DEFINES " !define MUI_STARTMENUPAGE_DEFAULTFOLDER \\\"Peerplays\\\"") # it seems like windows zip files usually don't have a single directory inside them, unix tgz frequently do SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) @@ -220,3 +241,4 @@ endif(LINUX) include(CPack) endif(ENABLE_INSTALLER) + diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 18ca3130..cf2355f1 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -1,12 +1,10 @@ -add_subdirectory( fc ) -add_subdirectory( db ) -#add_subdirectory( deterministic_openssl_rand ) +add_subdirectory( app ) add_subdirectory( chain ) +add_subdirectory( db ) add_subdirectory( egenesis ) +add_subdirectory( fc ) add_subdirectory( net ) -#add_subdirectory( p2p ) +add_subdirectory( plugins ) add_subdirectory( time ) add_subdirectory( utilities ) -add_subdirectory( app ) -add_subdirectory( plugins ) add_subdirectory( wallet ) diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index e0e5e6c2..52460c77 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -4,16 +4,19 @@ file(GLOB EGENESIS_HEADERS "../egenesis/include/graphene/app/*.hpp") add_library( graphene_app api.cpp application.cpp + config_util.cpp database_api.cpp plugin.cpp - config_util.cpp ${HEADERS} ${EGENESIS_HEADERS} ) # 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 graphene_market_history graphene_account_history graphene_accounts_list graphene_affiliate_stats graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness graphene_bookie graphene_elasticsearch peerplays_sidechain ) +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 ) + target_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" ) @@ -30,3 +33,26 @@ INSTALL( TARGETS ARCHIVE DESTINATION lib ) INSTALL( FILES ${HEADERS} DESTINATION "include/graphene/app" ) + + + +add_library( graphene_plugin + plugin.cpp + + include/graphene/app/plugin.hpp + ) + +target_link_libraries( graphene_plugin + PUBLIC graphene_net graphene_utilities ) + +target_include_directories( graphene_plugin + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + +INSTALL( TARGETS + graphene_app + + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 0cf3cbb3..f36fd8d3 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -579,7 +579,10 @@ namespace graphene { namespace app { { FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_get_account_history, + "Number of querying accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_get_account_history) ); + vector result; account_id_type account; try { @@ -627,13 +630,16 @@ namespace graphene { namespace app { { FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_get_account_history_operations, + "Number of querying history accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_get_account_history_operations) ); + vector result; account_id_type account; try { account = database_api.get_account_id_from_string(account_id_or_name); } catch (...) { return result; } - + const auto& stats = account(db).statistics(db); if( stats.most_recent_op == account_transaction_history_id_type() ) return result; const account_transaction_history_object* node = &stats.most_recent_op(db); @@ -667,7 +673,10 @@ namespace graphene { namespace app { { FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); - FC_ASSERT(limit <= 100); + FC_ASSERT( limit <= api_limit_get_relative_account_history, + "Number of querying accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_get_relative_account_history) ); + vector result; account_id_type account; try { @@ -797,14 +806,16 @@ namespace graphene { namespace app { } // asset_api - asset_api::asset_api(graphene::app::application& app) : + asset_api::asset_api(graphene::app::application& app) : _app(app), _db( *app.chain_database()), database_api( std::ref(*app.chain_database())) { } asset_api::~asset_api() { } vector asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const { - FC_ASSERT(limit <= 100); + FC_ASSERT( limit <= api_limit_get_asset_holders, + "Number of querying asset holder accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_get_asset_holders) ); asset_id_type asset_id = database_api.get_asset_id_from_string( asset ); const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >(); diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index cda9207a..ec4c71ad 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -380,7 +380,6 @@ namespace detail { _chain_db->enable_standby_votes_tracking( _options->at("enable-standby-votes-tracking").as() ); } - bool replay = false; std::string replay_reason = "reason not provided"; if( _options->count("replay-blockchain") ) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index a95a49c3..a0a7cfc2 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -234,8 +234,22 @@ class database_api_impl : public std::enable_shared_from_this vector get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const; vector get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const; + uint32_t api_limit_get_lower_bound_symbol = 100; + uint32_t api_limit_get_limit_orders = 300; + uint32_t api_limit_get_limit_orders_by_account = 101; + uint32_t api_limit_get_order_book = 50; + uint32_t api_limit_all_offers_count = 100; + uint32_t api_limit_lookup_accounts = 1000; + uint32_t api_limit_lookup_witness_accounts = 1000; + uint32_t api_limit_lookup_committee_member_accounts = 1000; + uint32_t api_limit_get_trade_history = 100; + uint32_t api_limit_get_trade_history_by_sequence = 100; + // Account Role vector get_account_roles_by_owner(account_id_type owner) const; + // rng + vector get_random_number_ex(uint64_t minimum, uint64_t maximum, uint64_t selections, bool duplicates) const; + uint64_t get_random_number(uint64_t bound) const; //private: const account_object* get_account_from_string( const std::string& name_or_id, @@ -877,7 +891,9 @@ map database_api::lookup_accounts(const string& lower_bo map database_api_impl::lookup_accounts(const string& lower_bound_name, uint32_t limit)const { - FC_ASSERT( limit <= 1000 ); + FC_ASSERT( limit <= api_limit_lookup_accounts, + "Number of querying accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_lookup_accounts) ); const auto& accounts_by_name = _db.get_index_type().indices().get(); map result; @@ -914,7 +930,7 @@ vector database_api::get_account_balances(const std::string& account_name return my->get_account_balances( account_name_or_id, assets ); } -vector database_api_impl::get_account_balances( const std::string& account_name_or_id, +vector database_api_impl::get_account_balances( const std::string& account_name_or_id, const flat_set& assets)const { const account_object* account = get_account_from_string(account_name_or_id); @@ -1085,7 +1101,9 @@ vector database_api::list_assets(const string& lower_bound_symbol, vector database_api_impl::list_assets(const string& lower_bound_symbol, uint32_t limit)const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_get_lower_bound_symbol, + "Number of querying accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_get_lower_bound_symbol) ); const auto& assets_by_symbol = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -1535,7 +1553,9 @@ order_book database_api::get_order_book( const string& base, const string& quote order_book database_api_impl::get_order_book( const string& base, const string& quote, unsigned limit )const { using boost::multiprecision::uint128_t; - FC_ASSERT( limit <= 50 ); + FC_ASSERT( limit <= api_limit_get_order_book, + "Number of querying accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_get_order_book) ); order_book result; result.base = base; @@ -1597,7 +1617,9 @@ vector database_api_impl::get_trade_history( const string& base, fc::time_point_sec stop, unsigned limit )const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_get_trade_history, + "Number of querying accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_get_trade_history) ); auto assets = lookup_asset_symbols( {base, quote} ); FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) ); @@ -1716,7 +1738,9 @@ map database_api::lookup_witness_accounts(const string& map database_api_impl::lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const { - FC_ASSERT( limit <= 1000 ); + FC_ASSERT( limit <= api_limit_lookup_witness_accounts, + "Number of querying accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_lookup_witness_accounts) ); const auto& witnesses_by_id = _db.get_index_type().indices().get(); // we want to order witnesses by account name, but that name is in the account object @@ -1792,7 +1816,9 @@ map database_api::lookup_committee_member_acco map database_api_impl::lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const { - FC_ASSERT( limit <= 1000 ); + FC_ASSERT( limit <= api_limit_lookup_committee_member_accounts, + "Number of querying accounts can not be greater than ${configured_limit}", + ("configured_limit", api_limit_lookup_committee_member_accounts) ); const auto& committee_members_by_id = _db.get_index_type().indices().get(); // we want to order committee_members by account name, but that name is in the account object @@ -2546,18 +2572,8 @@ graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type share_type total_amount; auto balance_type = vesting_balance_type::gpos; -#ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX - // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset - auto vesting_balances_begin = - vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type(), balance_type)); - auto vesting_balances_end = - vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), balance_type, share_type())); - for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) - { - total_amount += vesting_balance_obj.balance.amount; - } -#else + // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset const vesting_balance_index& vesting_index = _db.get_index_type(); const auto& vesting_balances = vesting_index.indices().get(); for (const vesting_balance_object& vesting_balance_obj : vesting_balances) @@ -2567,7 +2583,6 @@ graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type total_amount += vesting_balance_obj.balance.amount; } } -#endif vector account_vbos; const time_point_sec now = _db.head_block_time(); @@ -2578,9 +2593,9 @@ graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type && balance.balance.asset_id == asset_id_type()) account_vbos.emplace_back(balance); }); - + share_type allowed_withdraw_amount = 0, account_vested_balance = 0; - + for (const vesting_balance_object& vesting_balance_obj : account_vbos) { account_vested_balance += vesting_balance_obj.balance.amount; @@ -2912,7 +2927,9 @@ vector database_api::list_offers(const offer_id_type lower_id, uin vector database_api_impl::list_offers(const offer_id_type lower_id, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -2932,7 +2949,9 @@ vector database_api::list_sell_offers(const offer_id_type lower_id vector database_api_impl::list_sell_offers(const offer_id_type lower_id, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -2958,7 +2977,9 @@ vector database_api::list_buy_offers(const offer_id_type lower_id, vector database_api_impl::list_buy_offers(const offer_id_type lower_id, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -2985,7 +3006,9 @@ vector database_api::list_offer_history(const offer_histor vector database_api_impl::list_offer_history(const offer_history_id_type lower_id, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& oh_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3005,7 +3028,9 @@ vector database_api::get_offers_by_issuer(const offer_id_type lowe vector database_api_impl::get_offers_by_issuer(const offer_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3029,7 +3054,9 @@ vector database_api::get_offers_by_item(const offer_id_type lower_ vector database_api_impl::get_offers_by_item(const offer_id_type lower_id, const nft_id_type item, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3064,7 +3091,9 @@ vector database_api::get_offer_history_by_bidder(const off vector database_api_impl::get_offer_history_by_issuer(const offer_history_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& oh_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3085,7 +3114,9 @@ vector database_api_impl::get_offer_history_by_issuer(cons vector database_api_impl::get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& oh_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3107,7 +3138,9 @@ vector database_api_impl::get_offer_history_by_item(const vector database_api_impl::get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= api_limit_all_offers_count, + "Number of querying offers can not be greater than ${configured_limit}", + ("configured_limit", api_limit_all_offers_count) ); const auto& oh_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3143,6 +3176,32 @@ vector database_api_impl::get_account_roles_by_owner(accoun } return result; } +////////////////////////////////////////////////////////////////////// +// // +// Random numbers // +// // +////////////////////////////////////////////////////////////////////// + +vector database_api::get_random_number_ex(uint64_t minimum, uint64_t maximum, uint64_t selections, bool duplicates) const +{ + return my->get_random_number_ex(minimum, maximum, selections, duplicates); +} + +vector database_api_impl::get_random_number_ex(uint64_t minimum, uint64_t maximum, uint64_t selections, bool duplicates) const +{ + return _db.get_random_numbers(minimum, maximum, selections, duplicates); +} + +uint64_t database_api::get_random_number(uint64_t bound) const +{ + return my->get_random_number(bound); +} + +uint64_t database_api_impl::get_random_number(uint64_t bound) const { + vector v = get_random_number_ex(0, bound, 1, false); + return v.at(0); +} + ////////////////////////////////////////////////////////////////////// // // // Private methods // diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 4adf73a3..e4329141 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -150,6 +150,9 @@ namespace graphene { namespace app { fc::time_point_sec start, fc::time_point_sec end )const; vector list_core_accounts()const; flat_set get_market_history_buckets()const; + uint32_t api_limit_get_account_history_operations = 100; + uint32_t api_limit_get_account_history = 100; + uint32_t api_limit_get_relative_account_history = 100; private: application& _app; graphene::app::database_api database_api; @@ -354,6 +357,7 @@ namespace graphene { namespace app { */ vector get_all_asset_holders() const; + uint32_t api_limit_get_asset_holders = 100; private: graphene::app::application& _app; graphene::chain::database& _db; diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index ec5f8c1a..5b275f3f 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -934,7 +934,28 @@ class database_api // ACCOUNT ROLE // ////////////////// vector get_account_roles_by_owner(account_id_type owner) const; -private: + + ///////////////////////////// + // Random number generator // + ///////////////////////////// + /** + * @brief Returns the random number + * @param minimum Lower bound of segment containing random number + * @param maximum Upper bound of segment containing random number + * @param selections Number of random numbers to return + * @param duplicates Allow duplicated numbers + * @return Vector containing random numbers from segment [minimum, maximum) + */ + vector get_random_number_ex(uint64_t minimum, uint64_t maximum, uint64_t selections, bool duplicates) const; + + /** + * @brief Returns the random number + * @param bound Upper bound of segment containing random number + * @return Random number from segment [0, bound) + */ + uint64_t get_random_number(uint64_t bound) const; + + private: std::shared_ptr< database_api_impl > my; }; @@ -1125,4 +1146,7 @@ FC_API(graphene::app::database_api, // Account Roles (get_account_roles_by_owner) + // rngs + (get_random_number_ex) + (get_random_number) ) diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 0a0e9c56..4054878c 100755 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -8,143 +8,29 @@ add_dependencies( build_hardfork_hpp cat-parts ) file(GLOB HEADERS "include/graphene/chain/*.hpp") file(GLOB PROTOCOL_HEADERS "include/graphene/chain/protocol/*.hpp") -if( GRAPHENE_DISABLE_UNITY_BUILD ) - set( GRAPHENE_DB_FILES - db_balance.cpp - db_bet.cpp - db_block.cpp - db_debug.cpp - db_getter.cpp - db_init.cpp - db_maint.cpp - db_management.cpp - db_market.cpp - db_update.cpp - db_witness_schedule.cpp - ) +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 ) - set( GRAPHENE_DB_FILES - database.cpp ) - message( STATUS "Graphene database unity build enabled" ) -endif( GRAPHENE_DISABLE_UNITY_BUILD ) +#else( GRAPHENE_DISABLE_UNITY_BUILD ) +# list(FILTER CPP_FILES EXCLUDE REGEX ".*db_.*[.]cpp$") +# #message ("--- ${CPP_FILES}") +# message( STATUS "Graphene database unity build enabled" ) +#endif( GRAPHENE_DISABLE_UNITY_BUILD ) -## SORT .cpp by most likely to change / break compile add_library( graphene_chain - - # As database takes the longest to compile, start it first - ${GRAPHENE_DB_FILES} - fork_database.cpp - - protocol/types.cpp - protocol/address.cpp - protocol/authority.cpp - protocol/asset.cpp - protocol/assert.cpp - protocol/account.cpp - protocol/transfer.cpp - protocol/chain_parameters.cpp - protocol/committee_member.cpp - protocol/witness.cpp - protocol/market.cpp - protocol/proposal.cpp - protocol/withdraw_permission.cpp - protocol/asset_ops.cpp - protocol/lottery_ops.cpp - protocol/memo.cpp - protocol/worker.cpp - protocol/custom.cpp - protocol/operations.cpp - protocol/transaction.cpp - protocol/block.cpp - protocol/fee_schedule.cpp - protocol/confidential.cpp - protocol/vote.cpp - protocol/tournament.cpp - protocol/small_ops.cpp - protocol/custom_permission.cpp - protocol/custom_account_authority.cpp - protocol/offer.cpp - - genesis_state.cpp - get_config.cpp - - pts_address.cpp - - evaluator.cpp - balance_evaluator.cpp - account_evaluator.cpp - assert_evaluator.cpp - witness_evaluator.cpp - committee_member_evaluator.cpp - asset_evaluator.cpp - lottery_evaluator.cpp - transfer_evaluator.cpp - proposal_evaluator.cpp - market_evaluator.cpp - vesting_balance_evaluator.cpp - tournament_evaluator.cpp - tournament_object.cpp - match_object.cpp - game_object.cpp - withdraw_permission_evaluator.cpp - worker_evaluator.cpp - confidential_evaluator.cpp - special_authority.cpp - buyback.cpp - - account_object.cpp - asset_object.cpp - fba_object.cpp - proposal_object.cpp - vesting_balance_object.cpp - small_objects.cpp - - block_database.cpp - - is_authorized_asset.cpp - - protocol/sport.cpp - sport_evaluator.cpp - protocol/event_group.cpp - event_group_evaluator.cpp - event_group_object.cpp - protocol/event.cpp - event_evaluator.cpp - event_object.cpp - protocol/betting_market.cpp - betting_market_evaluator.cpp - betting_market_object.cpp - betting_market_group_object.cpp - custom_permission_evaluator.cpp - custom_account_authority_evaluator.cpp - - affiliate_payout.cpp - - offer_object.cpp - offer_evaluator.cpp - nft_evaluator.cpp - protocol/nft.cpp - protocol/account_role.cpp - account_role_evaluator.cpp - - son_evaluator.cpp - son_object.cpp - - son_wallet_evaluator.cpp - son_wallet_deposit_evaluator.cpp - son_wallet_withdraw_evaluator.cpp - - sidechain_address_evaluator.cpp - sidechain_transaction_evaluator.cpp - + ${CPP_FILES} + ${PROTOCOL_CPP_FILES} ${HEADERS} ${PROTOCOL_HEADERS} "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" ) add_dependencies( graphene_chain build_hardfork_hpp ) -target_link_libraries( graphene_chain fc graphene_db ) +target_link_libraries( graphene_chain graphene_db ) target_include_directories( graphene_chain PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" ) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 985fb8df..1ffcf3bc 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -596,7 +596,6 @@ void_result asset_update_dividend_evaluator::do_apply( const asset_update_divide obj.referrer = op.issuer; obj.lifetime_referrer = op.issuer(db()).lifetime_referrer; - auto& params = db().get_global_properties().parameters; obj.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; obj.lifetime_referrer_fee_percentage = GRAPHENE_DEFAULT_LIFETIME_REFERRER_PERCENT_OF_FEE; obj.referrer_rewards_percentage = GRAPHENE_DEFAULT_LIFETIME_REFERRER_PERCENT_OF_FEE; diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 79ad88ad..70adbde8 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -266,7 +266,7 @@ map< account_id_type, vector< uint16_t > > asset_object::distribute_winners_part *t += percents_to_distribute / holders.size(); } auto sweeps_distribution_percentage = db.get_global_properties().parameters.sweeps_distribution_percentage(); - for( int c = 0; c < winner_numbers.size(); ++c ) { + for( size_t c = 0; c < winner_numbers.size(); ++c ) { auto winner_num = winner_numbers[c]; lottery_reward_operation reward_op; reward_op.lottery = get_id(); diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 1e124902..8c1287c3 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -30,6 +30,6 @@ #include "db_maint.cpp" #include "db_management.cpp" #include "db_market.cpp" +#include "db_notify.cpp" #include "db_update.cpp" #include "db_witness_schedule.cpp" -#include "db_notify.cpp" \ No newline at end of file diff --git a/libraries/chain/db_balance.cpp b/libraries/chain/db_balance.cpp index 55729050..27a7e79e 100644 --- a/libraries/chain/db_balance.cpp +++ b/libraries/chain/db_balance.cpp @@ -140,8 +140,10 @@ void database::adjust_sweeps_vesting_balance(account_id_type account, int64_t de b.balance = delta; }); } else { - if( delta < 0 ) - FC_ASSERT( itr->get_balance() >= -delta, "Insufficient Balance: ${a}'s balance of ${b} is less than required ${r}", ("a",account)("b",itr->get_balance())("r",-delta)); + if( delta < 0 ) { + uint64_t delta_uint64 = -delta; + FC_ASSERT( itr->get_balance() >= delta_uint64, "Insufficient Balance: ${a}'s balance of ${b} is less than required ${r}", ("a",account)("b",itr->get_balance())("r",-delta)); + } modify(*itr, [&delta,&asset_id,this](sweeps_vesting_balance_object& b) { b.adjust_balance( asset( delta, asset_id ) ); b.last_claim_date = head_block_time(); diff --git a/libraries/chain/db_bet.cpp b/libraries/chain/db_bet.cpp index 8c3e1357..6b14f4ff 100644 --- a/libraries/chain/db_bet.cpp +++ b/libraries/chain/db_bet.cpp @@ -303,8 +303,6 @@ void database::settle_betting_market_group(const betting_market_group_object& be remove(betting_market); } - const event_object& event = betting_market_group.event_id(*this); - fc_dlog(fc::logger::get("betting"), "removing betting market group ${id}", ("id", betting_market_group.id)); remove(betting_market_group); @@ -537,11 +535,9 @@ int match_bet(database& db, const bet_object& taker_bet, const bet_object& maker // because we matched at the maker's odds and not the taker's odds, the remaining amount to match // may not be an even multiple of the taker's odds; round it down. share_type taker_remaining_factor = unrounded_taker_remaining_amount_to_match / takers_odds_maker_odds_ratio; - share_type taker_remaining_maker_amount_to_match = taker_remaining_factor * takers_odds_maker_odds_ratio; share_type taker_remaining_bet_amount = taker_remaining_factor * takers_odds_taker_odds_ratio; taker_refund_amount = taker_bet.amount_to_bet.amount - taker_amount_to_match - taker_remaining_bet_amount; - //idump((taker_remaining_factor)(taker_remaining_maker_amount_to_match)(taker_remaining_bet_amount)(taker_refund_amount)); } if (taker_refund_amount > share_type()) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 21701a25..67601c2e 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -715,7 +715,8 @@ void database::_apply_block( const signed_block& next_block ) perform_chain_maintenance(next_block, global_props); check_ending_lotteries(); - + check_ending_nft_lotteries(); + create_block_summary(next_block); place_delayed_bets(); // must happen after update_global_dynamic_data() updates the time clear_expired_transactions(); diff --git a/libraries/chain/db_getter.cpp b/libraries/chain/db_getter.cpp index 7588c9fe..cb7e1bc0 100644 --- a/libraries/chain/db_getter.cpp +++ b/libraries/chain/db_getter.cpp @@ -109,7 +109,7 @@ uint32_t database::last_non_undoable_block_num() const return head_block_num() - _undo_db.size(); } -std::vector database::get_seeds(asset_id_type for_asset, uint8_t count_winners) const +std::vector database::get_seeds( asset_id_type for_asset, uint8_t count_winners ) const { FC_ASSERT( count_winners <= 64 ); std::string salted_string = std::string(_random_number_generator._seed) + std::to_string(for_asset.instance.value); @@ -315,4 +315,36 @@ bool database::is_son_active( son_id_type son_id ) return (it_son != active_son_ids.end()); } +vector database::get_random_numbers(uint64_t minimum, uint64_t maximum, uint64_t selections, bool duplicates) +{ + FC_ASSERT( selections <= 100000 ); + if (duplicates == false) { + FC_ASSERT( maximum - minimum >= selections ); + } + + vector v; + v.reserve(selections); + + if (duplicates) { + for (uint64_t i = 0; i < selections; i++) { + int64_t rnd = get_random_bits(maximum - minimum) + minimum; + v.push_back(rnd); + } + } else { + vector tmpv; + tmpv.reserve(selections); + for (uint64_t i = minimum; i < maximum; i++) { + tmpv.push_back(i); + } + + for (uint64_t i = 0; (i < selections) && (tmpv.size() > 0); i++) { + uint64_t idx = get_random_bits(tmpv.size()); + v.push_back(tmpv.at(idx)); + tmpv.erase(tmpv.begin() + idx); + } + } + + return v; +} + } } diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 43ba381d..724cad85 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include @@ -94,12 +95,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include @@ -203,6 +206,12 @@ const uint8_t offer_history_object::type_id; const uint8_t account_role_object::space_id; const uint8_t account_role_object::type_id; +const uint8_t nft_lottery_balance_object::space_id; +const uint8_t nft_lottery_balance_object::type_id; + +const uint8_t random_number_object::space_id; +const uint8_t random_number_object::type_id; + void database::initialize_evaluators() { _operation_evaluators.resize(255); @@ -295,6 +304,9 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); + register_evaluator(); + register_evaluator(); + register_evaluator(); register_evaluator(); register_evaluator(); register_evaluator(); @@ -314,6 +326,7 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); + register_evaluator(); } void database::initialize_indexes() @@ -403,7 +416,9 @@ void database::initialize_indexes() add_index< primary_index >(); add_index< primary_index >(); add_index< primary_index >(); + add_index< primary_index >(); add_index< primary_index >(); + add_index< primary_index >(); } @@ -933,7 +948,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) const auto& idx = get_index_type().indices().get(); auto it = idx.begin(); - bool has_imbalanced_assets = false; while( it != idx.end() ) { @@ -945,7 +959,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) FC_ASSERT( debt_itr != total_debts.end() ); if( supply_itr->second != debt_itr->second ) { - has_imbalanced_assets = true; elog( "Genesis for asset ${aname} is not balanced\n" " Debt is ${debt}\n" " Supply is ${supply}\n", @@ -957,10 +970,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) } ++it; } -// @romek -#if 0 - FC_ASSERT( !has_imbalanced_assets ); -#endif // Save tallied supplies for( const auto& item : total_supplies ) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index a64b6d65..d695bb0f 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -32,24 +32,24 @@ #include #include +#include #include #include #include #include #include +#include #include #include #include #include #include +#include #include #include #include #include #include -#include - -#define USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX // vesting_balance_object by_asset_balance index needed namespace graphene { namespace chain { @@ -1190,7 +1190,6 @@ uint32_t database::get_gpos_current_subperiod() const auto period_start = fc::time_point_sec(gpo.parameters.gpos_period_start()); // variables needed - const fc::time_point_sec period_end = period_start + vesting_period; const auto number_of_subperiods = vesting_period / vesting_subperiod; const auto now = this->head_block_time(); auto seconds_since_period_start = now.sec_since_epoch() - period_start.sec_since_epoch(); @@ -1383,7 +1382,6 @@ void schedule_pending_dividend_balances(database& db, uint32_t holder_account_count = 0; -#ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset auto vesting_balances_begin = vesting_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id, balance_type)); @@ -1398,22 +1396,6 @@ void schedule_pending_dividend_balances(database& db, ("owner", vesting_balance_obj.owner(db).name) ("amount", vesting_balance_obj.balance.amount)); } -#else - // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset - const auto& vesting_balances = vesting_index.indices().get(); - for (const vesting_balance_object& vesting_balance_obj : vesting_balances) - { - if (vesting_balance_obj.balance.asset_id == dividend_holder_asset_obj.id && vesting_balance_obj.balance.amount && - vesting_balance_object.balance_type == balance_type) - { - vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; - ++gpos_holder_account_count; - dlog("Vesting balance for account: ${owner}, amount: ${amount}", - ("owner", vesting_balance_obj.owner(db).name) - ("amount", vesting_balance_obj.balance.amount)); - } - } -#endif auto current_distribution_account_balance_iter = current_distribution_account_balance_range.begin(); if(db.head_block_time() < HARDFORK_GPOS_TIME) @@ -1867,7 +1849,6 @@ void process_dividend_assets(database& db) { // if there was a previous payout, make our next payment one interval uint32_t current_time_sec = current_head_block_time.sec_since_epoch(); - fc::time_point_sec reference_time = *dividend_data_obj.last_scheduled_payout_time; uint32_t next_possible_time_sec = dividend_data_obj.last_scheduled_payout_time->sec_since_epoch(); do next_possible_time_sec += *dividend_data_obj.options.payout_interval; @@ -1988,7 +1969,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g balance_type = vesting_balance_type::gpos; const vesting_balance_index& vesting_index = d.get_index_type(); -#ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX + auto vesting_balances_begin = vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type(), balance_type)); auto vesting_balances_end = @@ -2000,19 +1981,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g ("owner", vesting_balance_obj.owner(d).name) ("amount", vesting_balance_obj.balance.amount)); } -#else - const auto& vesting_balances = vesting_index.indices().get(); - for (const vesting_balance_object& vesting_balance_obj : vesting_balances) - { - if (vesting_balance_obj.balance.asset_id == asset_id_type() && vesting_balance_obj.balance.amount && vesting_balance_obj.balance_type == balance_type) - { - vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; - dlog("Vesting balance for account: ${owner}, amount: ${amount}", - ("owner", vesting_balance_obj.owner(d).name) - ("amount", vesting_balance_obj.balance.amount)); - } - } -#endif + } void operator()( const account_object& stake_account, const account_statistics_object& stats ) diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index c6380b8c..e82602b1 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -107,7 +108,6 @@ void database::reindex( fc::path data_dir ) ilog( "reindexing blockchain" ); auto start = fc::time_point::now(); const auto last_block_num = last_block->block_num(); - uint32_t flush_point = last_block_num < 10000 ? 0 : last_block_num - 10000; uint32_t undo_point = last_block_num < 50 ? 0 : last_block_num - 50; ilog( "Replaying blocks, starting at ${next}...", ("next",head_block_num() + 1) ); @@ -123,8 +123,7 @@ void database::reindex( fc::path data_dir ) } for( uint32_t i = head_block_num() + 1; i <= last_block_num; ++i ) { - if( i % 10000 == 0 ) std::cerr << " " << double(i*100)/last_block_num << "% "<().indices().get(); + const auto& lotteries_idx = get_index_type().indices().get(); for( auto checking_asset: lotteries_idx ) { FC_ASSERT( checking_asset.is_lottery() ); @@ -306,6 +305,24 @@ void database::check_ending_lotteries() } catch( ... ) {} } +void database::check_ending_nft_lotteries() +{ + try { + const auto &nft_lotteries_idx = get_index_type().indices().get(); + for (auto checking_token : nft_lotteries_idx) + { + FC_ASSERT(checking_token.is_lottery()); + const auto &lottery_options = checking_token.lottery_data->lottery_options; + FC_ASSERT(lottery_options.is_active); + // Check the current supply of lottery tokens + auto current_supply = checking_token.get_token_current_supply(*this); + if ((lottery_options.ending_on_soldout && (current_supply == checking_token.max_supply)) || + (lottery_options.end_date != time_point_sec() && (lottery_options.end_date <= head_block_time()))) + checking_token.end_lottery(*this); + } + } catch( ... ) {} +} + void database::check_lottery_end_by_participants( asset_id_type asset_id ) { try { diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index 06ffdee5..c5986fad 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -41,6 +42,10 @@ #include #include #include +#include +#include +#include +#include using namespace fc; @@ -359,6 +364,13 @@ struct get_impacted_account_visitor void operator()( const account_role_delete_operation& op ){ _impacted.insert( op.owner ); } + void operator()( const nft_lottery_token_purchase_operation& op ){ + _impacted.insert( op.buyer ); + } + void operator()( const nft_lottery_reward_operation& op ) { + _impacted.insert( op.winner ); + } + void operator()( const nft_lottery_end_operation& op ) {} void operator()( const son_create_operation& op ) { _impacted.insert( op.owner_account ); } @@ -416,6 +428,9 @@ struct get_impacted_account_visitor void operator()( const sidechain_transaction_settle_operation& op ) { _impacted.insert( op.payer ); } + void operator()( const random_number_store_operation& op ) { + _impacted.insert( op.account ); + } }; void graphene::chain::operation_get_impacted_accounts( const operation& op, flat_set& result, bool ignore_custom_operation_required_auths ) { @@ -528,6 +543,9 @@ void get_relevant_accounts( const object* obj, flat_set& accoun } case sidechain_transaction_object_type:{ break; } + default: { + break; + } } } else if( obj->id.space() == implementation_ids ) @@ -582,6 +600,10 @@ void get_relevant_accounts( const object* obj, flat_set& accoun break; case impl_fba_accumulator_object_type: break; + case impl_nft_lottery_balance_object_type: + break; + default: + break; } } } // end get_relevant_accounts( const object* obj, flat_set& accounts ) diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 2e896070..0476982c 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -26,16 +26,18 @@ #include #include +#include +#include #include #include #include +#include #include +#include +#include #include #include #include -#include -#include -#include #include @@ -46,7 +48,6 @@ namespace graphene { namespace chain { void database::update_global_dynamic_data( const signed_block& b, const uint32_t missed_blocks ) { const dynamic_global_property_object& _dgp = get_dynamic_global_properties(); - const global_property_object& gpo = get_global_properties(); // dynamic global properties updating modify( _dgp, [&b,this,missed_blocks]( dynamic_global_property_object& dgp ){ diff --git a/libraries/chain/include/graphene/chain/account_role_object.hpp b/libraries/chain/include/graphene/chain/account_role_object.hpp index 2b3be409..ccdfc9bc 100644 --- a/libraries/chain/include/graphene/chain/account_role_object.hpp +++ b/libraries/chain/include/graphene/chain/account_role_object.hpp @@ -46,4 +46,4 @@ namespace graphene } // namespace graphene FC_REFLECT_DERIVED(graphene::chain::account_role_object, (graphene::db::object), - (owner)(name)(metadata)(allowed_operations)(whitelisted_accounts)(valid_to)) \ No newline at end of file + (owner)(name)(metadata)(allowed_operations)(whitelisted_accounts)(valid_to)) diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 41c1aa2b..9e154347 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -286,6 +286,7 @@ namespace graphene { namespace chain { void check_lottery_end_by_participants( asset_id_type asset_id ); void check_ending_lotteries(); + void check_ending_nft_lotteries(); //////////////////// db_getter.cpp //////////////////// @@ -324,6 +325,7 @@ namespace graphene { namespace chain { uint32_t last_non_undoable_block_num() const; vector get_account_custom_authorities(account_id_type account, const operation& op)const; + vector get_random_numbers(uint64_t minimum, uint64_t maximum, uint64_t selections, bool duplicates); //////////////////// db_init.cpp //////////////////// void initialize_evaluators(); 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 7c557be5..6ded103a 100644 --- a/libraries/chain/include/graphene/chain/global_betting_statistics_object.hpp +++ b/libraries/chain/include/graphene/chain/global_betting_statistics_object.hpp @@ -37,7 +37,7 @@ class global_betting_statistics_object : public graphene::db::abstract_object< g static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_global_betting_statistics_object_type; - uint32_t number_of_active_events; + uint32_t number_of_active_events = 0; map total_amount_staked; }; diff --git a/libraries/chain/include/graphene/chain/impacted.hpp b/libraries/chain/include/graphene/chain/impacted.hpp index fae276f7..3e070ce6 100644 --- a/libraries/chain/include/graphene/chain/impacted.hpp +++ b/libraries/chain/include/graphene/chain/impacted.hpp @@ -38,4 +38,4 @@ void transaction_get_impacted_accounts( const graphene::chain::transaction& tx, fc::flat_set& result, bool ignore_custom_operation_required_auths ); -} } // graphene::app \ No newline at end of file +} } // graphene::app diff --git a/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp b/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp new file mode 100644 index 00000000..0839cbbd --- /dev/null +++ b/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp @@ -0,0 +1,39 @@ +#pragma once +#include +#include +#include + +namespace graphene +{ + namespace chain + { + + class nft_lottery_token_purchase_evaluator : public evaluator + { + public: + typedef nft_lottery_token_purchase_operation operation_type; + + void_result do_evaluate(const nft_lottery_token_purchase_operation &o); + object_id_type do_apply(const nft_lottery_token_purchase_operation &o); + }; + + class nft_lottery_reward_evaluator : public evaluator + { + public: + typedef nft_lottery_reward_operation operation_type; + + void_result do_evaluate(const nft_lottery_reward_operation &o); + void_result do_apply(const nft_lottery_reward_operation &o); + }; + + class nft_lottery_end_evaluator : public evaluator + { + public: + typedef nft_lottery_end_operation operation_type; + + void_result do_evaluate(const nft_lottery_end_operation &o); + void_result do_apply(const nft_lottery_end_operation &o); + }; + + } // namespace chain +} // namespace graphene diff --git a/libraries/chain/include/graphene/chain/nft_object.hpp b/libraries/chain/include/graphene/chain/nft_object.hpp index 6a150852..fe026da5 100644 --- a/libraries/chain/include/graphene/chain/nft_object.hpp +++ b/libraries/chain/include/graphene/chain/nft_object.hpp @@ -6,6 +6,29 @@ namespace graphene { namespace chain { using namespace graphene::db; + class nft_lottery_balance_object : public abstract_object + { + public: + static const uint8_t space_id = implementation_ids; + static const uint8_t type_id = impl_nft_lottery_balance_object_type; + + // Total Progressive jackpot carried over from previous lotteries + asset total_progressive_jackpot; + // Current total jackpot in this lottery inclusive of the progressive jackpot + asset jackpot; + // Total tickets sold + share_type sweeps_tickets_sold; + }; + + struct nft_lottery_data + { + nft_lottery_data() {} + nft_lottery_data(const nft_lottery_options &options, nft_lottery_balance_id_type lottery_id) + : lottery_options(options), lottery_balance_id(lottery_id) {} + nft_lottery_options lottery_options; + nft_lottery_balance_id_type lottery_balance_id; + }; + class nft_metadata_object : public abstract_object { public: @@ -21,6 +44,21 @@ namespace graphene { namespace chain { bool is_transferable = false; bool is_sellable = true; optional account_role; + share_type max_supply = GRAPHENE_MAX_SHARE_SUPPLY; + optional lottery_data; + + nft_metadata_id_type get_id() const { return id; } + bool is_lottery() const { return lottery_data.valid(); } + uint32_t get_owner_num() const { return owner.instance.value; } + time_point_sec get_lottery_expiration() const; + asset get_lottery_jackpot(const database &db) const; + share_type get_token_current_supply(const database &db) const; + vector get_holders(const database &db) const; + vector get_ticket_ids(const database &db) const; + void distribute_benefactors_part(database &db); + map> distribute_winners_part(database &db); + void distribute_sweeps_holders_part(database &db); + void end_lottery(database &db); }; class nft_object : public abstract_object @@ -36,8 +74,23 @@ namespace graphene { namespace chain { std::string token_uri; }; + struct nft_lottery_comparer + { + bool operator()(const nft_metadata_object& lhs, const nft_metadata_object& rhs) const + { + if ( !lhs.is_lottery() ) return false; + if ( !lhs.lottery_data->lottery_options.is_active && !rhs.is_lottery()) return true; // not active lotteries first, just assets then + if ( !lhs.lottery_data->lottery_options.is_active ) return false; + if ( lhs.lottery_data->lottery_options.is_active && ( !rhs.is_lottery() || !rhs.lottery_data->lottery_options.is_active ) ) return true; + return lhs.get_lottery_expiration() > rhs.get_lottery_expiration(); + } + }; + struct by_name; struct by_symbol; + struct active_nft_lotteries; + struct by_nft_lottery; + struct by_nft_lottery_owner; using nft_metadata_multi_index_type = multi_index_container< nft_metadata_object, indexed_by< @@ -49,6 +102,34 @@ namespace graphene { namespace chain { >, ordered_unique< tag, member + >, + ordered_non_unique< tag, + identity< nft_metadata_object >, + nft_lottery_comparer + >, + ordered_unique< tag, + composite_key< + nft_metadata_object, + const_mem_fun, + member + >, + composite_key_compare< + std::greater< bool >, + std::greater< object_id_type > + > + >, + ordered_unique< tag, + composite_key< + nft_metadata_object, + const_mem_fun, + const_mem_fun, + member + >, + composite_key_compare< + std::greater< bool >, + std::greater< uint32_t >, + std::greater< object_id_type > + > > > >; @@ -86,8 +167,23 @@ namespace graphene { namespace chain { >; using nft_index = generic_index; + using nft_lottery_balance_index_type = multi_index_container< + nft_lottery_balance_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > > + > + >; + using nft_lottery_balance_index = generic_index; + } } // graphene::chain +FC_REFLECT_DERIVED( graphene::chain::nft_lottery_balance_object, (graphene::db::object), + (total_progressive_jackpot) + (jackpot) + (sweeps_tickets_sold) ) + +FC_REFLECT( graphene::chain::nft_lottery_data, (lottery_options)(lottery_balance_id) ) + FC_REFLECT_DERIVED( graphene::chain::nft_metadata_object, (graphene::db::object), (owner) (name) @@ -97,7 +193,9 @@ FC_REFLECT_DERIVED( graphene::chain::nft_metadata_object, (graphene::db::object) (revenue_split) (is_transferable) (is_sellable) - (account_role) ) + (account_role) + (max_supply) + (lottery_data) ) FC_REFLECT_DERIVED( graphene::chain::nft_object, (graphene::db::object), (nft_metadata_id) diff --git a/libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp b/libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp new file mode 100644 index 00000000..0c8ea855 --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp @@ -0,0 +1,86 @@ +#pragma once +#include +#include + +namespace graphene +{ + namespace chain + { + struct nft_lottery_token_purchase_operation : public base_operation + { + struct fee_parameters_type + { + uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; + }; + asset fee; + // Lottery NFT Metadata + nft_metadata_id_type lottery_id; + // Buyer purchasing lottery tickets + account_id_type buyer; + // count of tickets to buy + uint64_t tickets_to_buy; + // amount that can spent + asset amount; + + extensions_type extensions; + + account_id_type fee_payer() const { return buyer; } + void validate() const; + share_type calculate_fee(const fee_parameters_type &k) const; + }; + + struct nft_lottery_reward_operation : public base_operation + { + struct fee_parameters_type + { + uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; + }; + + asset fee; + // Lottery NFT Metadata + nft_metadata_id_type lottery_id; + // winner account + account_id_type winner; + // amount that won + asset amount; + // percentage of jackpot that user won + uint16_t win_percentage; + // true if recieved from benefators section of lottery; false otherwise + bool is_benefactor_reward; + + uint64_t winner_ticket_id; + + extensions_type extensions; + + account_id_type fee_payer() const { return account_id_type(); } + void validate() const {}; + share_type calculate_fee(const fee_parameters_type &k) const { return k.fee; }; + }; + + struct nft_lottery_end_operation : public base_operation + { + struct fee_parameters_type + { + uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; + }; + + asset fee; + // Lottery NFT Metadata + nft_metadata_id_type lottery_id; + + extensions_type extensions; + + account_id_type fee_payer() const { return account_id_type(); } + void validate() const {} + share_type calculate_fee(const fee_parameters_type &k) const { return k.fee; } + }; + + } // namespace chain +} // 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 diff --git a/libraries/chain/include/graphene/chain/protocol/nft_ops.hpp b/libraries/chain/include/graphene/chain/protocol/nft_ops.hpp index 4facf51a..1802623f 100644 --- a/libraries/chain/include/graphene/chain/protocol/nft_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/nft_ops.hpp @@ -4,6 +4,29 @@ namespace graphene { namespace chain { + struct nft_lottery_benefactor { + account_id_type id; + uint16_t share; // percent * GRAPHENE_1_PERCENT + nft_lottery_benefactor() = default; + nft_lottery_benefactor( const nft_lottery_benefactor & ) = default; + nft_lottery_benefactor( account_id_type _id, uint16_t _share ) : id( _id ), share( _share ) {} + }; + + struct nft_lottery_options + { + std::vector benefactors; + // specifying winning tickets as shares that will be issued + std::vector winning_tickets; + asset ticket_price; + time_point_sec end_date; + bool ending_on_soldout; + bool is_active; + bool delete_tickets_after_draw = false; + std::vector progressive_jackpots; + + void validate() const; + }; + struct nft_metadata_create_operation : public base_operation { struct fee_parameters_type @@ -23,6 +46,10 @@ namespace graphene { namespace chain { bool is_sellable = true; // Accounts Role optional account_role; + // Max number of NFTs that can be minted from the metadata + optional max_supply; + // Lottery configuration + optional lottery_options; extensions_type extensions; account_id_type fee_payer()const { return owner; } @@ -133,6 +160,9 @@ namespace graphene { namespace chain { } } // graphene::chain +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::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) ) @@ -140,7 +170,7 @@ FC_REFLECT( graphene::chain::nft_safe_transfer_from_operation::fee_parameters_ty 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::chain::nft_metadata_create_operation, (fee) (owner) (name) (symbol) (base_uri) (revenue_partner) (revenue_split) (is_transferable) (is_sellable) (account_role) (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) ) diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index 1a1222a5..83d347ab 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -50,12 +50,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include namespace graphene { namespace chain { @@ -184,7 +186,11 @@ namespace graphene { namespace chain { sidechain_transaction_create_operation, sidechain_transaction_sign_operation, sidechain_transaction_send_operation, - sidechain_transaction_settle_operation + sidechain_transaction_settle_operation, + nft_lottery_token_purchase_operation, + nft_lottery_reward_operation, + nft_lottery_end_operation, + random_number_store_operation > operation; /// @} // operations group diff --git a/libraries/chain/include/graphene/chain/protocol/random_number.hpp b/libraries/chain/include/graphene/chain/protocol/random_number.hpp new file mode 100644 index 00000000..3dbe487f --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/random_number.hpp @@ -0,0 +1,25 @@ +#pragma once + +namespace graphene { namespace chain { + + struct random_number_store_operation : public base_operation + { + struct fee_parameters_type { uint64_t fee = 5000 * GRAPHENE_BLOCKCHAIN_PRECISION; }; + + asset fee; + + account_id_type account; + vector random_number; + std::string data; + + account_id_type fee_payer()const { return account; } + }; + +} } // graphene::chain + +FC_REFLECT( graphene::chain::random_number_store_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::random_number_store_operation, (fee) + (account) + (random_number) + (data) ) + diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 56a4bb1c..321b08d9 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -183,6 +183,7 @@ namespace graphene { namespace chain { 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 }; @@ -214,7 +215,8 @@ namespace graphene { namespace chain { impl_sweeps_vesting_balance_object_type, impl_offer_history_object_type, impl_son_statistics_object_type, - impl_son_schedule_object_type + impl_son_schedule_object_type, + impl_nft_lottery_balance_object_type }; //typedef fc::unsigned_int object_id_type; @@ -258,6 +260,7 @@ namespace graphene { namespace chain { 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; @@ -297,6 +300,7 @@ namespace graphene { namespace chain { 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; @@ -321,6 +325,7 @@ namespace graphene { namespace chain { 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; @@ -352,6 +357,7 @@ namespace graphene { namespace chain { 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; @@ -496,6 +502,7 @@ FC_REFLECT_ENUM( graphene::chain::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, @@ -526,6 +533,7 @@ FC_REFLECT_ENUM( graphene::chain::impl_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 ) @@ -575,6 +583,7 @@ 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 ) @@ -582,7 +591,7 @@ 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, ) diff --git a/libraries/chain/include/graphene/chain/random_number_evaluator.hpp b/libraries/chain/include/graphene/chain/random_number_evaluator.hpp new file mode 100644 index 00000000..a26b9f3e --- /dev/null +++ b/libraries/chain/include/graphene/chain/random_number_evaluator.hpp @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include +#include + +namespace graphene { namespace chain { + + class random_number_store_evaluator : public evaluator + { + public: + typedef random_number_store_operation operation_type; + + void_result do_evaluate( const random_number_store_operation& o ); + object_id_type do_apply( const random_number_store_operation& o ); + }; + +} } // graphene::chain + diff --git a/libraries/chain/include/graphene/chain/random_number_object.hpp b/libraries/chain/include/graphene/chain/random_number_object.hpp new file mode 100644 index 00000000..3613d7a1 --- /dev/null +++ b/libraries/chain/include/graphene/chain/random_number_object.hpp @@ -0,0 +1,41 @@ +#pragma once + +namespace graphene { namespace chain { + using namespace graphene::db; + + class random_number_object : public abstract_object + { + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = random_number_object_type; + + account_id_type account; /* account who requested random number */ + time_point_sec timestamp; /* date and time when the number is read */ + vector random_number; /* random number(s) */ + std::string data; /* custom data in json format */ + }; + + struct by_account; + struct by_timestamp; + using random_number_multi_index_type = multi_index_container< + random_number_object, + indexed_by< + ordered_unique< tag, + member + >, + ordered_non_unique< tag, + member + >, + ordered_non_unique< tag, + member + > + > + >; + using random_number_index = generic_index; + +} } // graphene::chain + +FC_REFLECT_DERIVED( graphene::chain::random_number_object, (graphene::db::object), + (account) (timestamp) + (random_number) (data) ) + diff --git a/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp b/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp index 21cf492f..7e2e8c7c 100644 --- a/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp +++ b/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp @@ -57,6 +57,9 @@ namespace graphene case operation::tag::value: case operation::tag::value: case operation::tag::value: + case operation::tag::value: + case operation::tag::value: + case operation::tag::value: FC_ASSERT(block_time >= HARDFORK_NFT_TIME, "Custom permissions and roles not allowed on this operation yet!"); break; default: diff --git a/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp b/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp index e9011ffb..da39f636 100644 --- a/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp @@ -26,7 +26,7 @@ namespace graphene { namespace chain { static const uint8_t space_id = protocol_ids; static const uint8_t type_id = sidechain_transaction_object_type; - sidechain_type sidechain; + sidechain_type sidechain = sidechain_type::unknown; object_id_type object_id; std::string transaction; std::vector signers; @@ -37,7 +37,7 @@ namespace graphene { namespace chain { uint32_t current_weight = 0; uint32_t threshold = 0; - sidechain_transaction_status status; + sidechain_transaction_status status = sidechain_transaction_status::invalid; }; struct by_object_id; diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 1e87246e..998950bf 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -200,6 +200,20 @@ namespace graphene { namespace chain { */ struct by_account; struct by_asset_balance; + + struct by_asset_balance_helper_asset_id { + typedef asset_id_type result_type; + result_type operator()(const vesting_balance_object& vbo) const { + return vbo.balance.asset_id; + } + }; + struct by_asset_balance_helper_asset_amount { + typedef share_type result_type; + result_type operator()(const vesting_balance_object& vbo) const { + return vbo.balance.amount; + } + }; + typedef multi_index_container< vesting_balance_object, indexed_by< @@ -210,11 +224,9 @@ namespace graphene { namespace chain { ordered_non_unique< tag, composite_key< vesting_balance_object, - member_offset, + by_asset_balance_helper_asset_id, member, - member_offset - //member - //member_offset + by_asset_balance_helper_asset_amount >, composite_key_compare< std::less< asset_id_type >, diff --git a/libraries/chain/index.cpp b/libraries/chain/index.cpp deleted file mode 100644 index 41a469b2..00000000 --- a/libraries/chain/index.cpp +++ /dev/null @@ -1,43 +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 - -namespace graphene { namespace chain { - void base_primary_index::save_undo( const object& obj ) - { _db.save_undo( obj ); } - - void base_primary_index::on_add( const object& obj ) - { - _db.save_undo_add( obj ); - for( auto ob : _observers ) ob->on_add( obj ); - } - - void base_primary_index::on_remove( const object& obj ) - { _db.save_undo_remove( obj ); for( auto ob : _observers ) ob->on_remove( obj ); } - - void base_primary_index::on_modify( const object& obj ) - {for( auto ob : _observers ) ob->on_modify( obj ); } -} } // graphene::chain diff --git a/libraries/chain/nft_evaluator.cpp b/libraries/chain/nft_evaluator.cpp index f7f007ff..eedbd5cc 100644 --- a/libraries/chain/nft_evaluator.cpp +++ b/libraries/chain/nft_evaluator.cpp @@ -24,6 +24,26 @@ void_result nft_metadata_create_evaluator::do_evaluate( const nft_metadata_creat const auto& ar_obj = (*op.account_role)(db()); FC_ASSERT(ar_obj.owner == op.owner, "Only the Account Role created by the owner can be attached"); } + + // Lottery Related + if (!op.lottery_options) { + return void_result(); + } + FC_ASSERT((*op.lottery_options).end_date > now || (*op.lottery_options).end_date == time_point_sec()); + if (op.max_supply) { + FC_ASSERT(*op.max_supply >= 5); + } + + for(auto lottery_id: (*op.lottery_options).progressive_jackpots) { + const auto& lottery_obj = lottery_id(db()); + FC_ASSERT(lottery_obj.owner == op.owner, "Only the Owner can attach progressive jackpots"); + FC_ASSERT(lottery_obj.is_lottery(), "Only lottery objects can be attached as progressive jackpots"); + FC_ASSERT(lottery_obj.lottery_data->lottery_options.is_active == false, "Lottery should not be active"); + FC_ASSERT(lottery_obj.lottery_data->lottery_options.ticket_price.asset_id == (*op.lottery_options).ticket_price.asset_id, "Lottery asset type should be same"); + const auto& lottery_balance_obj = lottery_obj.lottery_data->lottery_balance_id(db()); + FC_ASSERT(lottery_balance_obj.jackpot.amount > 0, "Non zero progressive jackpot not allowed"); + } + return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -39,6 +59,26 @@ object_id_type nft_metadata_create_evaluator::do_apply( const nft_metadata_creat obj.is_transferable = op.is_transferable; obj.is_sellable = op.is_sellable; obj.account_role = op.account_role; + if (op.max_supply) { + obj.max_supply = *op.max_supply; + } + if (op.lottery_options) { + asset jackpot_sum(0,(*op.lottery_options).ticket_price.asset_id); + for(auto lottery_id: (*op.lottery_options).progressive_jackpots) { + const auto& lottery_obj = lottery_id(db()); + const auto& lottery_balance_obj = lottery_obj.lottery_data->lottery_balance_id(db()); + FC_ASSERT(lottery_balance_obj.jackpot.amount > 0, "Non zero progressive jackpot not allowed"); + db().modify(lottery_balance_obj, [&] ( nft_lottery_balance_object& nlbo ) { + jackpot_sum += nlbo.jackpot; + nlbo.jackpot -= nlbo.jackpot; + }); + } + const auto& new_lottery_balance_obj = db().create([&](nft_lottery_balance_object& nlbo) { + nlbo.total_progressive_jackpot = jackpot_sum; + nlbo.jackpot = jackpot_sum; + }); + obj.lottery_data = nft_lottery_data(*op.lottery_options, new_lottery_balance_obj.id); + } }); return new_nft_metadata_object.id; } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -110,6 +150,7 @@ void_result nft_mint_evaluator::do_evaluate( const nft_mint_operation& op ) FC_ASSERT( itr_nft_md != idx_nft_md.end(), "NFT metadata not found" ); FC_ASSERT( itr_nft_md->owner == op.payer, "Only metadata owner can mint NFT" ); + FC_ASSERT(itr_nft_md->get_token_current_supply(db()) < itr_nft_md->max_supply, "NFTs can't be minted more than max_supply"); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/chain/nft_lottery_evaluator.cpp b/libraries/chain/nft_lottery_evaluator.cpp new file mode 100644 index 00000000..794616cf --- /dev/null +++ b/libraries/chain/nft_lottery_evaluator.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include + +namespace graphene +{ + namespace chain + { + void_result nft_lottery_token_purchase_evaluator::do_evaluate(const nft_lottery_token_purchase_operation &op) + { + try + { + const database &d = db(); + auto now = d.head_block_time(); + FC_ASSERT(now >= HARDFORK_NFT_TIME, "Not allowed until NFT HF"); + op.buyer(d); + const auto &lottery_md_obj = op.lottery_id(d); + FC_ASSERT(lottery_md_obj.is_lottery(), "Not a lottery type"); + if (lottery_md_obj.account_role) + { + const auto &ar_idx = d.get_index_type().indices().get(); + auto ar_itr = ar_idx.find(*lottery_md_obj.account_role); + if (ar_itr != ar_idx.end()) + { + FC_ASSERT(d.account_role_valid(*ar_itr, op.buyer, get_type()), "Account role not valid"); + } + } + + auto lottery_options = lottery_md_obj.lottery_data->lottery_options; + FC_ASSERT(lottery_options.ticket_price.asset_id == op.amount.asset_id); + FC_ASSERT((double)op.amount.amount.value / lottery_options.ticket_price.amount.value == (double)op.tickets_to_buy); + return void_result(); + } + FC_CAPTURE_AND_RETHROW((op)) + } + + object_id_type nft_lottery_token_purchase_evaluator::do_apply(const nft_lottery_token_purchase_operation &op) + { + try + { + transaction_evaluation_state nft_mint_context(&db()); + nft_mint_context.skip_fee_schedule_check = true; + const auto &lottery_md_obj = op.lottery_id(db()); + nft_id_type nft_id; + for (size_t i = 0; i < op.tickets_to_buy; i++) + { + nft_mint_operation mint_op; + mint_op.payer = lottery_md_obj.owner; + mint_op.nft_metadata_id = lottery_md_obj.id; + mint_op.owner = op.buyer; + nft_id = db().apply_operation(nft_mint_context, mint_op).get(); + } + db().adjust_balance(op.buyer, -op.amount); + db().modify(lottery_md_obj.lottery_data->lottery_balance_id(db()), [&](nft_lottery_balance_object &obj) { + obj.jackpot += op.amount; + }); + return nft_id; + } + FC_CAPTURE_AND_RETHROW((op)) + } + + void_result nft_lottery_reward_evaluator::do_evaluate(const nft_lottery_reward_operation &op) + { + try + { + const database &d = db(); + auto now = d.head_block_time(); + FC_ASSERT(now >= HARDFORK_NFT_TIME, "Not allowed until NFT HF"); + op.winner(d); + + const auto &lottery_md_obj = op.lottery_id(d); + FC_ASSERT(lottery_md_obj.is_lottery()); + + const auto &lottery_options = lottery_md_obj.lottery_data->lottery_options; + FC_ASSERT(lottery_options.is_active); + FC_ASSERT(lottery_md_obj.get_lottery_jackpot(d) >= op.amount); + return void_result(); + } + FC_CAPTURE_AND_RETHROW((op)) + } + + void_result nft_lottery_reward_evaluator::do_apply(const nft_lottery_reward_operation &op) + { + try + { + const auto &lottery_md_obj = op.lottery_id(db()); + db().adjust_balance(op.winner, op.amount); + db().modify(lottery_md_obj.lottery_data->lottery_balance_id(db()), [&](nft_lottery_balance_object &obj) { + obj.jackpot -= op.amount; + }); + return void_result(); + } + FC_CAPTURE_AND_RETHROW((op)) + } + + void_result nft_lottery_end_evaluator::do_evaluate(const nft_lottery_end_operation &op) + { + try + { + const database &d = db(); + auto now = d.head_block_time(); + FC_ASSERT(now >= HARDFORK_NFT_TIME, "Not allowed until NFT HF"); + const auto &lottery_md_obj = op.lottery_id(d); + FC_ASSERT(lottery_md_obj.is_lottery()); + + const auto &lottery_options = lottery_md_obj.lottery_data->lottery_options; + FC_ASSERT(lottery_options.is_active); + FC_ASSERT(lottery_md_obj.get_lottery_jackpot(d).amount == 0); + return void_result(); + } + FC_CAPTURE_AND_RETHROW((op)) + } + + void_result nft_lottery_end_evaluator::do_apply(const nft_lottery_end_operation &op) + { + try + { + const auto &lottery_md_obj = op.lottery_id(db()); + db().modify(lottery_md_obj, [&](nft_metadata_object &obj) { + obj.lottery_data->lottery_options.is_active = false; + }); + db().modify(lottery_md_obj.lottery_data->lottery_balance_id(db()), [&](nft_lottery_balance_object &obj) { + obj.sweeps_tickets_sold = lottery_md_obj.get_token_current_supply(db()); + }); + + if (lottery_md_obj.lottery_data->lottery_options.delete_tickets_after_draw) + { + const auto &nft_index_by_md = db().get_index_type().indices().get(); + auto delete_nft_itr = nft_index_by_md.lower_bound(op.lottery_id); + while (delete_nft_itr != nft_index_by_md.end() && delete_nft_itr->nft_metadata_id == op.lottery_id) + { + const nft_object &nft_obj = *delete_nft_itr; + ++delete_nft_itr; + db().remove(nft_obj); + } + } + + return void_result(); + } + FC_CAPTURE_AND_RETHROW((op)) + } + } // namespace chain +} // namespace graphene \ No newline at end of file diff --git a/libraries/chain/nft_lottery_object.cpp b/libraries/chain/nft_lottery_object.cpp new file mode 100644 index 00000000..f5e9f674 --- /dev/null +++ b/libraries/chain/nft_lottery_object.cpp @@ -0,0 +1,171 @@ +#include +#include + +namespace graphene +{ + namespace chain + { + time_point_sec nft_metadata_object::get_lottery_expiration() const + { + if (lottery_data) + return lottery_data->lottery_options.end_date; + return time_point_sec(); + } + + asset nft_metadata_object::get_lottery_jackpot(const database &db) const + { + if (lottery_data) + return lottery_data->lottery_balance_id(db).jackpot; + return asset(); + } + + share_type nft_metadata_object::get_token_current_supply(const database &db) const + { + share_type current_supply; + const auto &idx_lottery_by_md = db.get_index_type().indices().get(); + auto lottery_range = idx_lottery_by_md.equal_range(id); + current_supply = std::distance(lottery_range.first, lottery_range.second); + return current_supply; + } + + vector nft_metadata_object::get_holders(const database &db) const + { + const auto &idx_lottery_by_md = db.get_index_type().indices().get(); + auto lottery_range = idx_lottery_by_md.equal_range(id); + vector holders; + holders.reserve(std::distance(lottery_range.first, lottery_range.second)); + std::for_each(lottery_range.first, lottery_range.second, + [&](const nft_object &ticket) { + holders.emplace_back(ticket.owner); + }); + return holders; + } + + vector nft_metadata_object::get_ticket_ids(const database &db) const + { + const auto &idx_lottery_by_md = db.get_index_type().indices().get(); + auto lottery_range = idx_lottery_by_md.equal_range(id); + vector tickets; + tickets.reserve(std::distance(lottery_range.first, lottery_range.second)); + std::for_each(lottery_range.first, lottery_range.second, + [&](const nft_object &ticket) { + tickets.emplace_back(ticket.id.instance()); + }); + return tickets; + } + + void nft_metadata_object::distribute_benefactors_part(database &db) + { + transaction_evaluation_state eval(&db); + const auto &lottery_options = lottery_data->lottery_options; + share_type jackpot = lottery_options.ticket_price.amount * get_token_current_supply(db) + lottery_data->lottery_balance_id(db).total_progressive_jackpot.amount; + + for (auto benefactor : lottery_options.benefactors) + { + nft_lottery_reward_operation reward_op; + reward_op.lottery_id = id; + reward_op.winner = benefactor.id; + reward_op.is_benefactor_reward = true; + reward_op.win_percentage = benefactor.share; + reward_op.amount = asset(jackpot.value * benefactor.share / GRAPHENE_100_PERCENT, lottery_options.ticket_price.asset_id); + db.apply_operation(eval, reward_op); + } + } + + map> nft_metadata_object::distribute_winners_part(database &db) + { + transaction_evaluation_state eval(&db); + auto current_supply = get_token_current_supply(db); + auto &lottery_options = lottery_data->lottery_options; + + auto holders = get_holders(db); + vector ticket_ids = get_ticket_ids(db); + FC_ASSERT(current_supply.value == (int64_t)holders.size()); + FC_ASSERT(get_lottery_jackpot(db).amount.value == current_supply.value * lottery_options.ticket_price.amount.value); + map> structurized_participants; + for (account_id_type holder : holders) + { + if (!structurized_participants.count(holder)) + structurized_participants.emplace(holder, vector()); + } + uint64_t jackpot = get_lottery_jackpot(db).amount.value; + auto selections = lottery_options.winning_tickets.size() <= holders.size() ? lottery_options.winning_tickets.size() : holders.size(); + auto winner_numbers = db.get_random_numbers(0, holders.size(), selections, false); + + auto &tickets(lottery_options.winning_tickets); + + if (holders.size() < tickets.size()) + { + uint16_t percents_to_distribute = 0; + for (auto i = tickets.begin() + holders.size(); i != tickets.end();) + { + percents_to_distribute += *i; + i = tickets.erase(i); + } + for (auto t = tickets.begin(); t != tickets.begin() + holders.size(); ++t) + *t += percents_to_distribute / holders.size(); + } + auto sweeps_distribution_percentage = db.get_global_properties().parameters.sweeps_distribution_percentage(); + for (size_t c = 0; c < winner_numbers.size(); ++c) + { + auto winner_num = winner_numbers[c]; + nft_lottery_reward_operation reward_op; + reward_op.lottery_id = id; + reward_op.is_benefactor_reward = false; + reward_op.winner = holders[winner_num]; + if (ticket_ids.size() > winner_num) + { + reward_op.winner_ticket_id = ticket_ids[winner_num]; + } + reward_op.win_percentage = tickets[c]; + reward_op.amount = asset(jackpot * tickets[c] * (1. - sweeps_distribution_percentage / (double)GRAPHENE_100_PERCENT) / GRAPHENE_100_PERCENT, lottery_options.ticket_price.asset_id); + db.apply_operation(eval, reward_op); + + structurized_participants[holders[winner_num]].push_back(tickets[c]); + } + return structurized_participants; + } + + void nft_metadata_object::distribute_sweeps_holders_part(database &db) + { + transaction_evaluation_state eval(&db); + auto &asset_bal_idx = db.get_index_type().indices().get(); + auto sweeps_params = db.get_global_properties().parameters; + uint64_t distribution_asset_supply = sweeps_params.sweeps_distribution_asset()(db).dynamic_data(db).current_supply.value; + const auto range = asset_bal_idx.equal_range(boost::make_tuple(sweeps_params.sweeps_distribution_asset())); + asset remaining_jackpot = get_lottery_jackpot(db); + uint64_t holders_sum = 0; + for (const account_balance_object &holder_balance : boost::make_iterator_range(range.first, range.second)) + { + int64_t holder_part = remaining_jackpot.amount.value / (double)distribution_asset_supply * holder_balance.balance.value * SWEEPS_VESTING_BALANCE_MULTIPLIER; + db.adjust_sweeps_vesting_balance(holder_balance.owner, holder_part); + holders_sum += holder_part; + } + uint64_t balance_rest = remaining_jackpot.amount.value * SWEEPS_VESTING_BALANCE_MULTIPLIER - holders_sum; + db.adjust_sweeps_vesting_balance(sweeps_params.sweeps_vesting_accumulator_account(), balance_rest); + db.modify(lottery_data->lottery_balance_id(db), [&](nft_lottery_balance_object &obj) { + obj.jackpot -= remaining_jackpot; + }); + } + + void nft_metadata_object::end_lottery(database &db) + { + transaction_evaluation_state eval(&db); + const auto &lottery_options = lottery_data->lottery_options; + + FC_ASSERT(is_lottery()); + FC_ASSERT(lottery_options.is_active && (lottery_options.end_date <= db.head_block_time() || lottery_options.ending_on_soldout)); + + auto participants = distribute_winners_part(db); + if (participants.size() > 0) + { + distribute_benefactors_part(db); + distribute_sweeps_holders_part(db); + } + + nft_lottery_end_operation end_op; + end_op.lottery_id = get_id(); + db.apply_operation(eval, end_op); + } + } // namespace chain +} // namespace graphene diff --git a/libraries/chain/proposal_evaluator.cpp b/libraries/chain/proposal_evaluator.cpp index 38521284..ac8ef601 100644 --- a/libraries/chain/proposal_evaluator.cpp +++ b/libraries/chain/proposal_evaluator.cpp @@ -219,6 +219,18 @@ struct proposal_operation_hardfork_visitor FC_ASSERT( block_time >= HARDFORK_NFT_TIME, "account_role_delete_operation not allowed yet!" ); } + void operator()(const nft_lottery_token_purchase_operation &v) const { + FC_ASSERT( block_time >= HARDFORK_NFT_TIME, "nft_lottery_token_purchase_operation not allowed yet!" ); + } + + void operator()(const nft_lottery_reward_operation &v) const { + FC_ASSERT( block_time >= HARDFORK_NFT_TIME, "nft_lottery_reward_operation not allowed yet!" ); + } + + void operator()(const nft_lottery_end_operation &v) const { + FC_ASSERT( block_time >= HARDFORK_NFT_TIME, "nft_lottery_end_operation not allowed yet!" ); + } + void operator()(const son_create_operation &v) const { FC_ASSERT( block_time >= HARDFORK_SON_TIME, "son_create_operation not allowed yet!" ); } diff --git a/libraries/chain/protocol/competitor.cpp b/libraries/chain/protocol/competitor.cpp deleted file mode 100644 index 1f35cf37..00000000 --- a/libraries/chain/protocol/competitor.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018 Peerplays Blockchain Standards Association, 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 - -namespace graphene { namespace chain { - -void competitor_create_operation::validate() const -{ - FC_ASSERT( fee.amount >= 0 ); -} - - -} } // graphene::chain - diff --git a/libraries/chain/protocol/nft.cpp b/libraries/chain/protocol/nft.cpp index 4a66f330..ca7fe816 100644 --- a/libraries/chain/protocol/nft.cpp +++ b/libraries/chain/protocol/nft.cpp @@ -45,6 +45,10 @@ void nft_metadata_create_operation::validate() const FC_ASSERT(fee.amount >= 0, "Fee must not be negative"); FC_ASSERT(is_valid_nft_token_name(name), "Invalid NFT name provided"); FC_ASSERT(is_valid_nft_token_name(symbol), "Invalid NFT symbol provided"); + if (lottery_options) + { + (*lottery_options).validate(); + } } void nft_metadata_update_operation::validate() const diff --git a/libraries/chain/protocol/nft_lottery.cpp b/libraries/chain/protocol/nft_lottery.cpp new file mode 100644 index 00000000..16454962 --- /dev/null +++ b/libraries/chain/protocol/nft_lottery.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +namespace graphene +{ + namespace chain + { + + void nft_lottery_options::validate() const + { + FC_ASSERT(winning_tickets.size() <= 64); + FC_ASSERT(ticket_price.amount >= 1); + uint16_t total = 0; + for (auto benefactor : benefactors) + { + total += benefactor.share; + } + for (auto share : winning_tickets) + { + total += share; + } + FC_ASSERT(total == GRAPHENE_100_PERCENT, "distribution amount not equals GRAPHENE_100_PERCENT"); + FC_ASSERT(ending_on_soldout == true || end_date != time_point_sec(), "lottery may not end"); + } + + share_type nft_lottery_token_purchase_operation::calculate_fee(const fee_parameters_type &k) const + { + return k.fee; + } + + void nft_lottery_token_purchase_operation::validate() const + { + 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 diff --git a/libraries/chain/random_number_evaluator.cpp b/libraries/chain/random_number_evaluator.cpp new file mode 100644 index 00000000..acfab042 --- /dev/null +++ b/libraries/chain/random_number_evaluator.cpp @@ -0,0 +1,24 @@ +#include +#include + +namespace graphene { namespace chain { + +void_result random_number_store_evaluator::do_evaluate( const random_number_store_operation& op ) +{ try { + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type random_number_store_evaluator::do_apply( const random_number_store_operation& op ) +{ try { + const auto& new_random_number_object = db().create( [&]( random_number_object& obj ) { + obj.account = op.account; + obj.timestamp = db().head_block_time(); + obj.random_number = op.random_number; + obj.data = op.data; + }); + return new_random_number_object.id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // graphene::chain + diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp index ad64b34f..056652e5 100644 --- a/libraries/chain/tournament_object.cpp +++ b/libraries/chain/tournament_object.cpp @@ -605,8 +605,9 @@ namespace graphene { namespace chain { return; // We shouldn't be here if the final match is complete - assert(last_complete_round != num_rounds - 1); - if (last_complete_round == num_rounds - 1) + uint32_t last_complete_round_uint32 = last_complete_round; + assert(last_complete_round_uint32 != num_rounds - 1); + if (last_complete_round_uint32 == num_rounds - 1) return; if (first_incomplete_match_was_waiting) diff --git a/libraries/chain/transaction_object.cpp b/libraries/chain/transaction_object.cpp deleted file mode 100644 index fb4f75df..00000000 --- a/libraries/chain/transaction_object.cpp +++ /dev/null @@ -1,95 +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 - -namespace graphene { namespace chain { - -const object* transaction_index::create(const std::function& constructor, object_id_type) -{ - transaction_object obj; - - obj.id = get_next_available_id(); - constructor(&obj); - - auto result = _index.insert(std::move(obj)); - FC_ASSERT(result.second, "Could not create transaction_object! Most likely a uniqueness constraint is violated."); - return &*result.first; -} - -void transaction_index::modify(const object* obj, - const std::function& m) -{ - assert(obj != nullptr); - FC_ASSERT(obj->id < _index.size()); - - const transaction_object* t = dynamic_cast(obj); - assert(t != nullptr); - - auto itr = _index.find(obj->id.instance()); - assert(itr != _index.end()); - _index.modify(itr, [&m](transaction_object& o) { m(&o); }); -} - -void transaction_index::add(unique_ptr o) -{ - assert(o); - object_id_type id = o->id; - assert(id.space() == transaction_object::space_id); - assert(id.type() == transaction_object::type_id); - assert(id.instance() == size()); - - auto trx = dynamic_cast(o.get()); - assert(trx != nullptr); - o.release(); - - auto result = _index.insert(std::move(*trx)); - FC_ASSERT(result.second, "Could not insert transaction_object! Most likely a uniqueness constraint is violated."); -} - -void transaction_index::remove(object_id_type id) -{ - auto& index = _index.get(); - auto itr = index.find(id.instance()); - if( itr == index.end() ) - return; - - assert(id.space() == transaction_object::space_id); - assert(id.type() == transaction_object::type_id); - - index.erase(itr); -} - -const object*transaction_index::get(object_id_type id) const -{ - if( id.type() != transaction_object::type_id || - id.space() != transaction_object::space_id ) - return nullptr; - - auto itr = _index.find(id.instance()); - if( itr == _index.end() ) - return nullptr; - return &*itr; -} - -} } // graphene::chain diff --git a/libraries/db/include/graphene/db/undo_database.hpp b/libraries/db/include/graphene/db/undo_database.hpp index 9f104869..4b727372 100644 --- a/libraries/db/include/graphene/db/undo_database.hpp +++ b/libraries/db/include/graphene/db/undo_database.hpp @@ -59,17 +59,7 @@ namespace graphene { namespace db { { mv._apply_undo = false; } - ~session() { - try { - if( _apply_undo ) _db.undo(); - } - catch ( const fc::exception& e ) - { - elog( "${e}", ("e",e.to_detail_string() ) ); - throw; // maybe crash.. - } - if( _disable_on_exit ) _db.disable(); - } + ~session(); void commit() { _apply_undo = false; _db.commit(); } void undo() { if( _apply_undo ) _db.undo(); _apply_undo = false; } void merge() { if( _apply_undo ) _db.merge(); _apply_undo = false; } diff --git a/libraries/db/undo_database.cpp b/libraries/db/undo_database.cpp index c5f2ef65..bffd761d 100644 --- a/libraries/db/undo_database.cpp +++ b/libraries/db/undo_database.cpp @@ -30,6 +30,18 @@ namespace graphene { namespace db { void undo_database::enable() { _disabled = false; } void undo_database::disable() { _disabled = true; } +undo_database::session::~session() { + try { + if( _apply_undo ) _db.undo(); + } + catch ( const fc::exception& e ) + { + elog( "${e}", ("e",e.to_detail_string() ) ); + std::terminate(); + } + if( _disable_on_exit ) _db.disable(); +} + undo_database::session undo_database::start_undo_session( bool force_enable ) { if( _disabled && !force_enable ) return session(*this); diff --git a/libraries/egenesis/CMakeLists.txt b/libraries/egenesis/CMakeLists.txt index 68de4b00..75589999 100644 --- a/libraries/egenesis/CMakeLists.txt +++ b/libraries/egenesis/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_egenesis_none include/graphene/egenesis/egenesis.hpp ) -target_link_libraries( graphene_egenesis_none graphene_chain fc ) +target_link_libraries( graphene_egenesis_none graphene_chain ) target_include_directories( graphene_egenesis_none PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) @@ -12,7 +12,7 @@ add_executable( embed_genesis embed_genesis.cpp ) -target_link_libraries( embed_genesis graphene_chain graphene_app graphene_egenesis_none fc ) +target_link_libraries( embed_genesis PRIVATE graphene_app graphene_egenesis_none ) set( embed_genesis_args -t "${CMAKE_CURRENT_SOURCE_DIR}/egenesis_brief.cpp.tmpl---${CMAKE_CURRENT_BINARY_DIR}/egenesis_brief.cpp" @@ -42,8 +42,8 @@ add_custom_command( add_library( graphene_egenesis_brief "${CMAKE_CURRENT_BINARY_DIR}/egenesis_brief.cpp" include/graphene/egenesis/egenesis.hpp ) add_library( graphene_egenesis_full "${CMAKE_CURRENT_BINARY_DIR}/egenesis_full.cpp" include/graphene/egenesis/egenesis.hpp ) -target_link_libraries( graphene_egenesis_brief graphene_chain fc ) -target_link_libraries( graphene_egenesis_full graphene_chain fc ) +target_link_libraries( graphene_egenesis_brief graphene_chain ) +target_link_libraries( graphene_egenesis_full graphene_chain ) target_include_directories( graphene_egenesis_brief PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/fc b/libraries/fc index fb27454c..48888392 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit fb27454cdf1626e5e108e42848bd1bcfe60c9540 +Subproject commit 488883921936139e8734b99822d3a589afe80da1 diff --git a/libraries/net/CMakeLists.txt b/libraries/net/CMakeLists.txt index 955012e4..1cc71728 100644 --- a/libraries/net/CMakeLists.txt +++ b/libraries/net/CMakeLists.txt @@ -10,12 +10,8 @@ set(SOURCES node.cpp add_library( graphene_net ${SOURCES} ${HEADERS} ) -target_link_libraries( graphene_net - PUBLIC fc graphene_db ) -target_include_directories( graphene_net - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../chain/include" "${CMAKE_CURRENT_BINARY_DIR}/../chain/include" -) +target_link_libraries( graphene_net graphene_chain ) +target_include_directories( graphene_net PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) if(MSVC) set_source_files_properties( node.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 14e32306..3222da08 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -2375,6 +2375,7 @@ namespace graphene { namespace net { namespace detail { VERIFY_CORRECT_THREAD(); item_hash_t reference_point = peer->last_block_delegate_has_seen; uint32_t reference_point_block_num = _delegate->get_block_number(peer->last_block_delegate_has_seen); + (void)reference_point_block_num; // when we call _delegate->get_blockchain_synopsis(), we may yield and there's a // chance this peer's state will change before we get control back. Save off @@ -3414,6 +3415,7 @@ namespace graphene { namespace net { namespace detail { for (const item_hash_t& transaction_message_hash : contained_transaction_message_ids) { size_t items_erased = _items_to_fetch.get().erase(item_id(trx_message_type, transaction_message_hash)); + (void)items_erased; // there are two ways we could behave here: we could either act as if we received // the transaction outside the block and offer it to our peers, or we could just // forget about it (we would still advertise this block to our peers so they should diff --git a/libraries/plugins/CMakeLists.txt b/libraries/plugins/CMakeLists.txt index d2a5be16..20497629 100644 --- a/libraries/plugins/CMakeLists.txt +++ b/libraries/plugins/CMakeLists.txt @@ -1,14 +1,14 @@ -add_subdirectory( witness ) add_subdirectory( account_history ) add_subdirectory( accounts_list ) add_subdirectory( affiliate_stats ) -add_subdirectory( elasticsearch ) -add_subdirectory( market_history ) -add_subdirectory( delayed_node ) add_subdirectory( bookie ) +add_subdirectory( debug_witness ) +add_subdirectory( delayed_node ) +add_subdirectory( elasticsearch ) +add_subdirectory( es_objects ) add_subdirectory( generate_genesis ) add_subdirectory( generate_uia_sharedrop_genesis ) -add_subdirectory( debug_witness ) -add_subdirectory( snapshot ) +add_subdirectory( market_history ) add_subdirectory( peerplays_sidechain ) -add_subdirectory( es_objects ) +add_subdirectory( snapshot ) +add_subdirectory( witness ) diff --git a/libraries/plugins/account_history/CMakeLists.txt b/libraries/plugins/account_history/CMakeLists.txt index 4af81abb..4a40fba8 100644 --- a/libraries/plugins/account_history/CMakeLists.txt +++ b/libraries/plugins/account_history/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_account_history account_history_plugin.cpp ) -target_link_libraries( graphene_account_history graphene_chain graphene_app ) +target_link_libraries( graphene_account_history PRIVATE graphene_plugin ) target_include_directories( graphene_account_history PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/accounts_list/CMakeLists.txt b/libraries/plugins/accounts_list/CMakeLists.txt index 3c2747c2..b337409e 100644 --- a/libraries/plugins/accounts_list/CMakeLists.txt +++ b/libraries/plugins/accounts_list/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_accounts_list accounts_list_plugin.cpp ) -target_link_libraries( graphene_accounts_list graphene_chain graphene_app ) +target_link_libraries( graphene_accounts_list PRIVATE graphene_plugin ) target_include_directories( graphene_accounts_list PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/affiliate_stats/CMakeLists.txt b/libraries/plugins/affiliate_stats/CMakeLists.txt index fec2544c..60b2d6e2 100644 --- a/libraries/plugins/affiliate_stats/CMakeLists.txt +++ b/libraries/plugins/affiliate_stats/CMakeLists.txt @@ -5,7 +5,7 @@ add_library( graphene_affiliate_stats affiliate_stats_plugin.cpp ) -target_link_libraries( graphene_affiliate_stats graphene_chain graphene_app ) +target_link_libraries( graphene_affiliate_stats PRIVATE graphene_plugin graphene_account_history ) target_include_directories( graphene_affiliate_stats PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/bookie/CMakeLists.txt b/libraries/plugins/bookie/CMakeLists.txt index 12d84e3c..d7c6d4c0 100644 --- a/libraries/plugins/bookie/CMakeLists.txt +++ b/libraries/plugins/bookie/CMakeLists.txt @@ -5,7 +5,7 @@ add_library( graphene_bookie bookie_api.cpp ) -target_link_libraries( graphene_bookie graphene_chain graphene_app ) +target_link_libraries( graphene_bookie PRIVATE graphene_plugin ) target_include_directories( graphene_bookie PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/debug_witness/CMakeLists.txt b/libraries/plugins/debug_witness/CMakeLists.txt index f0fcb7fb..ac7d7fc9 100644 --- a/libraries/plugins/debug_witness/CMakeLists.txt +++ b/libraries/plugins/debug_witness/CMakeLists.txt @@ -5,7 +5,7 @@ add_library( graphene_debug_witness debug_witness.cpp ) -target_link_libraries( graphene_debug_witness graphene_chain graphene_app ) +target_link_libraries( graphene_debug_witness PRIVATE graphene_plugin ) target_include_directories( graphene_debug_witness PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/delayed_node/CMakeLists.txt b/libraries/plugins/delayed_node/CMakeLists.txt index 63dd73e5..d481eb84 100644 --- a/libraries/plugins/delayed_node/CMakeLists.txt +++ b/libraries/plugins/delayed_node/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_delayed_node delayed_node_plugin.cpp ) -target_link_libraries( graphene_delayed_node graphene_chain graphene_app ) +target_link_libraries( graphene_delayed_node PRIVATE graphene_plugin graphene_accounts_list graphene_affiliate_stats graphene_bookie graphene_debug_witness graphene_elasticsearch graphene_market_history ) target_include_directories( graphene_delayed_node PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/elasticsearch/CMakeLists.txt b/libraries/plugins/elasticsearch/CMakeLists.txt index f4815576..928d2e3c 100644 --- a/libraries/plugins/elasticsearch/CMakeLists.txt +++ b/libraries/plugins/elasticsearch/CMakeLists.txt @@ -4,13 +4,21 @@ add_library( graphene_elasticsearch elasticsearch_plugin.cpp ) -target_link_libraries( graphene_elasticsearch graphene_chain graphene_app curl ) -target_include_directories( graphene_elasticsearch - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) +find_curl() +include_directories(${CURL_INCLUDE_DIRS}) if(MSVC) set_source_files_properties(elasticsearch_plugin.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) +if(CURL_STATICLIB) + SET_TARGET_PROPERTIES(graphene_elasticsearch PROPERTIES + COMPILE_DEFINITIONS "CURL_STATICLIB") +endif(CURL_STATICLIB) +target_link_libraries( graphene_elasticsearch PRIVATE graphene_plugin ${CURL_LIBRARIES} ) +target_include_directories( graphene_elasticsearch + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" + PUBLIC "${CURL_INCLUDE_DIR}" ) + install( TARGETS graphene_elasticsearch diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index dc167b05..8777c06d 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -57,9 +57,9 @@ class elasticsearch_plugin_impl bool _elasticsearch_visitor = false; std::string _elasticsearch_basic_auth = ""; std::string _elasticsearch_index_prefix = "peerplays-"; - bool _elasticsearch_operation_object = false; + bool _elasticsearch_operation_object = true; uint32_t _elasticsearch_start_es_after_block = 0; - bool _elasticsearch_operation_string = true; + bool _elasticsearch_operation_string = false; mode _elasticsearch_mode = mode::only_save; CURL *curl; // curl handler vector bulk_lines; // vector of op lines @@ -75,20 +75,19 @@ class elasticsearch_plugin_impl std::string bulk_line; std::string index_name; bool is_sync = false; - fc::time_point last_sync; private: bool add_elasticsearch( const account_id_type account_id, const optional& oho, const uint32_t block_number ); const account_transaction_history_object& addNewEntry(const account_statistics_object& stats_obj, - const account_id_type account_id, + const account_id_type& account_id, const optional & oho); - const account_statistics_object& getStatsObject(const account_id_type account_id); + const account_statistics_object& getStatsObject(const account_id_type& account_id); void growStats(const account_statistics_object& stats_obj, const account_transaction_history_object& ath); void getOperationType(const optional & oho); void doOperationHistory(const optional & oho); - void doBlock(const optional & oho, const signed_block& b); + void doBlock(uint32_t trx_in_block, const signed_block& b); void doVisitor(const optional & oho); void checkState(const fc::time_point_sec& block_time); - void cleanObjects(const account_transaction_history_object& ath, account_id_type account_id); + void cleanObjects(const account_transaction_history_id_type& ath, const account_id_type& account_id); void createBulkLine(const account_transaction_history_object& ath); void prepareBulk(const account_transaction_history_id_type& ath_id); void populateESstruct(); @@ -148,7 +147,7 @@ bool elasticsearch_plugin_impl::update_account_histories( const signed_block& b // populate what we can before impacted loop getOperationType(oho); doOperationHistory(oho); - doBlock(oho, b); + doBlock(oho->trx_in_block, b); if(_elasticsearch_visitor) doVisitor(oho); @@ -174,7 +173,11 @@ bool elasticsearch_plugin_impl::update_account_histories( const signed_block& b for( auto& account_id : impacted ) { if(!add_elasticsearch( account_id, oho, b.block_num() )) + { + elog( "Error adding data to Elastic Search: block num ${b}, account ${a}, data ${d}", + ("b",b.block_num()) ("a",account_id) ("d", oho) ); return false; + } } } // we send bulk at end of block when we are in sync for better real time client experience @@ -185,23 +188,33 @@ bool elasticsearch_plugin_impl::update_account_histories( const signed_block& b { prepare.clear(); if(!graphene::utilities::SendBulk(es)) + { + // Note: although called with `std::move()`, `es` is not updated in `SendBulk()` + elog( "Error sending ${n} lines of bulk data to Elastic Search, the first lines are:", + ("n",es.bulk_lines.size()) ); + for( size_t i = 0; i < es.bulk_lines.size() && i < 10; ++i ) + { + edump( (es.bulk_lines[i]) ); + } return false; + } else bulk_lines.clear(); } } + if(bulk_lines.size() != limit_documents) + bulk_lines.reserve(limit_documents); + return true; } void elasticsearch_plugin_impl::checkState(const fc::time_point_sec& block_time) { - fc::time_point current_time(fc::time_point::now()); - if(((current_time - block_time) < fc::seconds(30)) || (current_time - last_sync > fc::seconds(60))) + if((fc::time_point::now() - block_time) < fc::seconds(30)) { limit_documents = _elasticsearch_bulk_sync; is_sync = true; - last_sync = current_time; } else { @@ -232,11 +245,11 @@ void elasticsearch_plugin_impl::doOperationHistory(const optional op); } -void elasticsearch_plugin_impl::doBlock(const optional & oho, const signed_block& b) +void elasticsearch_plugin_impl::doBlock(uint32_t trx_in_block, const signed_block& b) { std::string trx_id = ""; - if(oho->trx_in_block < b.transactions.size()) - trx_id = b.transactions[oho->trx_in_block].id().str(); + if(trx_in_block < b.transactions.size()) + trx_id = b.transactions[trx_in_block].id().str(); bs.block_num = b.block_num(); bs.block_time = b.timestamp; bs.trx_id = trx_id; @@ -244,23 +257,41 @@ void elasticsearch_plugin_impl::doBlock(const optional & oho) { + graphene::chain::database& db = database(); + operation_visitor o_v; oho->op.visit(o_v); + auto fee_asset = o_v.fee_asset(db); vs.fee_data.asset = o_v.fee_asset; + vs.fee_data.asset_name = fee_asset.symbol; vs.fee_data.amount = o_v.fee_amount; + vs.fee_data.amount_units = (o_v.fee_amount.value)/(double)asset::scaled_precision(fee_asset.precision).value; + auto transfer_asset = o_v.transfer_asset_id(db); vs.transfer_data.asset = o_v.transfer_asset_id; + vs.transfer_data.asset_name = transfer_asset.symbol; vs.transfer_data.amount = o_v.transfer_amount; + vs.transfer_data.amount_units = (o_v.transfer_amount.value)/(double)asset::scaled_precision(transfer_asset.precision).value; vs.transfer_data.from = o_v.transfer_from; vs.transfer_data.to = o_v.transfer_to; + auto fill_pays_asset = o_v.fill_pays_asset_id(db); + auto fill_receives_asset = o_v.fill_receives_asset_id(db); vs.fill_data.order_id = o_v.fill_order_id; vs.fill_data.account_id = o_v.fill_account_id; vs.fill_data.pays_asset_id = o_v.fill_pays_asset_id; + vs.fill_data.pays_asset_name = fill_pays_asset.symbol; vs.fill_data.pays_amount = o_v.fill_pays_amount; + vs.fill_data.pays_amount_units = (o_v.fill_pays_amount.value)/(double)asset::scaled_precision(fill_pays_asset.precision).value; vs.fill_data.receives_asset_id = o_v.fill_receives_asset_id; + vs.fill_data.receives_asset_name = fill_receives_asset.symbol; vs.fill_data.receives_amount = o_v.fill_receives_amount; + vs.fill_data.receives_amount_units = (o_v.fill_receives_amount.value)/(double)asset::scaled_precision(fill_receives_asset.precision).value; + + auto fill_price = (o_v.fill_receives_amount.value/(double)asset::scaled_precision(fill_receives_asset.precision).value) / + (o_v.fill_pays_amount.value/(double)asset::scaled_precision(fill_pays_asset.precision).value); + vs.fill_data.fill_price_units = fill_price; //vs.fill_data.fill_price = o_v.fill_fill_price; //vs.fill_data.is_maker = o_v.fill_is_maker; } @@ -276,13 +307,22 @@ bool elasticsearch_plugin_impl::add_elasticsearch( const account_id_type account createBulkLine(ath); prepareBulk(ath.id); } - cleanObjects(ath, account_id); + cleanObjects(ath.id, account_id); if (curl && bulk_lines.size() >= limit_documents) { // we are in bulk time, ready to add data to elasticsearech prepare.clear(); populateESstruct(); if(!graphene::utilities::SendBulk(es)) + { + // Note: although called with `std::move()`, `es` is not updated in `SendBulk()` + elog( "Error sending ${n} lines of bulk data to Elastic Search, the first lines are:", + ("n",es.bulk_lines.size()) ); + for( size_t i = 0; i < es.bulk_lines.size() && i < 10; ++i ) + { + edump( (es.bulk_lines[i]) ); + } return false; + } else bulk_lines.clear(); } @@ -290,15 +330,16 @@ bool elasticsearch_plugin_impl::add_elasticsearch( const account_id_type account return true; } -const account_statistics_object& elasticsearch_plugin_impl::getStatsObject(const account_id_type account_id) +const account_statistics_object& elasticsearch_plugin_impl::getStatsObject(const account_id_type& account_id) { graphene::chain::database& db = database(); - const auto &acct = db.get(account_id); - return acct.statistics(db); + const auto &stats_obj = db.get_account_stats_by_owner(account_id); + + return stats_obj; } const account_transaction_history_object& elasticsearch_plugin_impl::addNewEntry(const account_statistics_object& stats_obj, - const account_id_type account_id, + const account_id_type& account_id, const optional & oho) { graphene::chain::database& db = database(); @@ -340,19 +381,21 @@ void elasticsearch_plugin_impl::prepareBulk(const account_transaction_history_id fc::mutable_variant_object bulk_header; bulk_header["_index"] = index_name; bulk_header["_type"] = "data"; - bulk_header["_id"] = fc::to_string(ath_id.space_id) + "." + fc::to_string(ath_id.type_id) + "." + ath_id.instance; - prepare = graphene::utilities::createBulk(bulk_header, bulk_line); - bulk_lines.insert(bulk_lines.end(), prepare.begin(), prepare.end()); + bulk_header["_id"] = fc::to_string(ath_id.space_id) + "." + fc::to_string(ath_id.type_id) + "." + + fc::to_string(ath_id.instance.value); + prepare = graphene::utilities::createBulk(bulk_header, std::move(bulk_line)); + std::move(prepare.begin(), prepare.end(), std::back_inserter(bulk_lines)); + prepare.clear(); } -void elasticsearch_plugin_impl::cleanObjects(const account_transaction_history_object& ath, account_id_type account_id) +void elasticsearch_plugin_impl::cleanObjects(const account_transaction_history_id_type& ath_id, const account_id_type& account_id) { graphene::chain::database& db = database(); // remove everything except current object from ath const auto &his_idx = db.get_index_type(); const auto &by_seq_idx = his_idx.indices().get(); auto itr = by_seq_idx.lower_bound(boost::make_tuple(account_id, 0)); - if (itr != by_seq_idx.end() && itr->account == account_id && itr->id != ath.id) { + if (itr != by_seq_idx.end() && itr->account == account_id && itr->id != ath_id) { // if found, remove the entry const auto remove_op_id = itr->operation_id; const auto itr_remove = itr; @@ -377,9 +420,12 @@ void elasticsearch_plugin_impl::cleanObjects(const account_transaction_history_o void elasticsearch_plugin_impl::populateESstruct() { es.curl = curl; - es.bulk_lines = bulk_lines; + es.bulk_lines = std::move(bulk_lines); es.elasticsearch_url = _elasticsearch_node_url; es.auth = _elasticsearch_basic_auth; + es.index_prefix = _elasticsearch_index_prefix; + es.endpoint = ""; + es.query = ""; } } // end namespace detail @@ -421,11 +467,11 @@ void elasticsearch_plugin::plugin_set_program_options( ("elasticsearch-index-prefix", boost::program_options::value(), "Add a prefix to the index(peerplays-)") ("elasticsearch-operation-object", boost::program_options::value(), - "Save operation as object(false)") + "Save operation as object(true)") ("elasticsearch-start-es-after-block", boost::program_options::value(), "Start doing ES job after block(0)") ("elasticsearch-operation-string", boost::program_options::value(), - "Save operation as string. Needed to serve history api calls(true)") + "Save operation as string. Needed to serve history api calls(false)") ("elasticsearch-mode", boost::program_options::value(), "Mode of operation: only_save(0), only_query(1), all(2) - Default: 0") ; @@ -467,18 +513,18 @@ void elasticsearch_plugin::plugin_initialize(const boost::program_options::varia if (options.count("elasticsearch-mode")) { const auto option_number = options["elasticsearch-mode"].as(); if(option_number > mode::all) - FC_THROW_EXCEPTION(fc::exception, "Elasticsearch mode not valid"); + FC_THROW_EXCEPTION(graphene::chain::plugin_exception, "Elasticsearch mode not valid"); my->_elasticsearch_mode = static_cast(options["elasticsearch-mode"].as()); } if(my->_elasticsearch_mode != mode::only_query) { if (my->_elasticsearch_mode == mode::all && !my->_elasticsearch_operation_string) - FC_THROW_EXCEPTION(fc::exception, + FC_THROW_EXCEPTION(graphene::chain::plugin_exception, "If elasticsearch-mode is set to all then elasticsearch-operation-string need to be true"); database().applied_block.connect([this](const signed_block &b) { if (!my->update_account_histories(b)) - FC_THROW_EXCEPTION(fc::exception, + FC_THROW_EXCEPTION(graphene::chain::plugin_exception, "Error populating ES database, we are going to keep trying."); }); } @@ -563,13 +609,12 @@ vector elasticsearch_plugin::get_account_history( const auto response = graphene::utilities::simpleQuery(es); variant variant_response = fc::json::from_string(response); - const auto hits = variant_response["hits"]["total"]["value"]; + const auto hits = variant_response["hits"]["total"]; uint32_t size; if( hits.is_object() ) // ES-7 ? size = static_cast(hits["value"].as_uint64()); else // probably ES-6 size = static_cast(hits.as_uint64()); - size = std::min( size, limit ); for(unsigned i=0; i #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include namespace graphene { namespace es_objects { @@ -61,6 +77,16 @@ class es_objects_plugin_impl bool _es_objects_balances = true; bool _es_objects_limit_orders = true; bool _es_objects_asset_bitasset = true; + + bool _es_objects_account_role = true; + bool _es_objects_committee_member = true; + bool _es_objects_nft = true; + bool _es_objects_son = true; + bool _es_objects_transaction = true; + bool _es_objects_vesting_balance = true; + bool _es_objects_witness = true; + bool _es_objects_worker = true; + std::string _es_objects_index_prefix = "ppobjects-"; uint32_t _es_objects_start_es_after_block = 0; CURL *curl; // curl handler @@ -79,7 +105,6 @@ class es_objects_plugin_impl bool es_objects_plugin_impl::genesis() { - ilog("elasticsearch OBJECTS: inserting data from genesis"); graphene::chain::database &db = _self.database(); @@ -112,13 +137,142 @@ bool es_objects_plugin_impl::genesis() }); } + if (_es_objects_account_role) { + 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, "account_role"); + }); + } + if (_es_objects_committee_member) { + 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, "committee_member"); + }); + } + if (_es_objects_nft) { + 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, "nft"); + }); + } + if (_es_objects_nft) { + 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, "nft_metadata"); + }); + } + if (_es_objects_nft) { + 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, "offer"); + }); + } + if (_es_objects_son) { + 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, "sidechain_address"); + }); + } + if (_es_objects_son) { + 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, "sidechain_transaction"); + }); + } + if (_es_objects_son) { + 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, "son"); + }); + } + if (_es_objects_son) { + 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, "son_proposal"); + }); + } + if (_es_objects_son) { + 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, "son_wallet"); + }); + } + if (_es_objects_son) { + 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, "son_wallet_deposit"); + }); + } + if (_es_objects_son) { + 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, "son_wallet_withdraw"); + }); + } + if (_es_objects_transaction) { + 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"); + }); + } + if (_es_objects_vesting_balance) { + 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, "vesting_balance"); + }); + } + if (_es_objects_witness) { + 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, "witness"); + }); + } + if (_es_objects_worker) { + 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, "worker"); + }); + } + graphene::utilities::ES es; es.curl = curl; es.bulk_lines = bulk; es.elasticsearch_url = _es_objects_elasticsearch_url; es.auth = _es_objects_auth; if (!graphene::utilities::SendBulk(es)) - FC_THROW_EXCEPTION(fc::exception, "Error inserting genesis data."); + FC_THROW_EXCEPTION(graphene::chain::plugin_exception, "Error inserting genesis data."); else bulk.clear(); @@ -197,6 +351,150 @@ bool es_objects_plugin_impl::index_database(const vector& ids, s else prepareTemplate(*ba, "bitasset"); } + } else if (value.is() && _es_objects_account_role) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "account_role"); + else + prepareTemplate(*ba, "account_role"); + } + } else if (value.is() && _es_objects_committee_member) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "committee_member"); + else + prepareTemplate(*ba, "committee_member"); + } + } else if (value.is() && _es_objects_nft) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "nft"); + else + prepareTemplate(*ba, "nft"); + } + } else if (value.is() && _es_objects_nft) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "nft_metadata"); + else + prepareTemplate(*ba, "nft_metadata"); + } + } else if (value.is() && _es_objects_nft) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "offer"); + else + prepareTemplate(*ba, "offer"); + } + } else if (value.is() && _es_objects_son) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "sidechain_address"); + else + prepareTemplate(*ba, "sidechain_address"); + } + } else if (value.is() && _es_objects_son) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "sidechain_transaction"); + else + prepareTemplate(*ba, "sidechain_transaction"); + } + } else if (value.is() && _es_objects_son) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "son"); + else + prepareTemplate(*ba, "son"); + } + } else if (value.is() && _es_objects_son) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "son_proposal"); + else + prepareTemplate(*ba, "son_proposal"); + } + } else if (value.is() && _es_objects_son) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "son_wallet"); + else + prepareTemplate(*ba, "son_wallet"); + } + } else if (value.is() && _es_objects_son) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "son_wallet_deposit"); + else + prepareTemplate(*ba, "son_wallet_deposit"); + } + } else if (value.is() && _es_objects_son) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "son_wallet_withdraw"); + else + prepareTemplate(*ba, "son_wallet_withdraw"); + } + } else if (value.is() && _es_objects_transaction) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "transaction"); + else + prepareTemplate(*ba, "transaction"); + } + } else if (value.is() && _es_objects_vesting_balance) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "vesting_balance"); + else + prepareTemplate(*ba, "vesting_balance"); + } + } else if (value.is() && _es_objects_witness) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "witness"); + else + prepareTemplate(*ba, "witness"); + } + } else if (value.is() && _es_objects_worker) { + auto obj = db.find_object(value); + auto ba = static_cast(obj); + if (ba != nullptr) { + if (action == "delete") + remove_from_database(ba->id, "worker"); + else + prepareTemplate(*ba, "worker"); + } } } @@ -296,52 +594,39 @@ void es_objects_plugin::plugin_set_program_options( ) { cli.add_options() - ("es-objects-elasticsearch-url", boost::program_options::value(), "Elasticsearch node url(http://localhost:9200/)") + ("es-objects-elasticsearch-url", boost::program_options::value(), + "Elasticsearch node url(http://localhost:9200/)") ("es-objects-auth", boost::program_options::value(), "Basic auth username:password('')") - ("es-objects-bulk-replay", boost::program_options::value(), "Number of bulk documents to index on replay(10000)") - ("es-objects-bulk-sync", boost::program_options::value(), "Number of bulk documents to index on a synchronized chain(100)") + ("es-objects-bulk-replay", boost::program_options::value(), + "Number of bulk documents to index on replay(10000)") + ("es-objects-bulk-sync", boost::program_options::value(), + "Number of bulk documents to index on a synchronized chain(100)") ("es-objects-proposals", boost::program_options::value(), "Store proposal objects(true)") ("es-objects-accounts", boost::program_options::value(), "Store account objects(true)") ("es-objects-assets", boost::program_options::value(), "Store asset objects(true)") ("es-objects-balances", boost::program_options::value(), "Store balances objects(true)") - ("es-objects-limit-orders", boost::program_options::value(), "Store limit order objects(true)") - ("es-objects-asset-bitasset", boost::program_options::value(), "Store feed data(true)") - ("es-objects-index-prefix", boost::program_options::value(), "Add a prefix to the index(ppobjects-)") - ("es-objects-keep-only-current", boost::program_options::value(), "Keep only current state of the objects(true)") - ("es-objects-start-es-after-block", boost::program_options::value(), "Start doing ES job after block(0)") + ("es-objects-limit-orders", boost::program_options::value(), "Store limit order objects(false)") + ("es-objects-bitasset", boost::program_options::value(), "Store feed data(true)") + ("es-objects-account-role", boost::program_options::value(), "Store account role objects (true)") + ("es-objects-committee-member", boost::program_options::value(), "Store committee member objects(true)") + ("es-objects-nft", boost::program_options::value(), "Store nft objects (true)") + ("es-objects-son", boost::program_options::value(), "Store son objects (true)") + ("es-objects-transaction", boost::program_options::value(), "Store transaction objects (true)") + ("es-objects-vesting-balance", boost::program_options::value(), "Store vesting balance objects (true)") + ("es-objects-witness", boost::program_options::value(), "Store witness objects (true)") + ("es-objects-worker", boost::program_options::value(), "Store worker objects (true)") + ("es-objects-index-prefix", boost::program_options::value(), + "Add a prefix to the index(ppobjects-)") + ("es-objects-keep-only-current", boost::program_options::value(), + "Keep only current state of the objects(true)") + ("es-objects-start-es-after-block", boost::program_options::value(), + "Start doing ES job after block(0)") ; cfg.add(cli); } void es_objects_plugin::plugin_initialize(const boost::program_options::variables_map& options) { - database().applied_block.connect([this](const signed_block &b) { - if(b.block_num() == 1) { - if (!my->genesis()) - FC_THROW_EXCEPTION(fc::exception, "Error populating genesis data."); - } - }); - - database().new_objects.connect([this]( const vector& ids, const flat_set& impacted_accounts ) { - if(!my->index_database(ids, "create")) - { - FC_THROW_EXCEPTION(fc::exception, "Error creating object from ES database, we are going to keep trying."); - } - }); - database().changed_objects.connect([this]( const vector& ids, const flat_set& impacted_accounts ) { - if(!my->index_database(ids, "update")) - { - FC_THROW_EXCEPTION(fc::exception, "Error updating object from ES database, we are going to keep trying."); - } - }); - database().removed_objects.connect([this](const vector& ids, const vector& objs, const flat_set& impacted_accounts) { - if(!my->index_database(ids, "delete")) - { - FC_THROW_EXCEPTION(fc::exception, "Error deleting object from ES database, we are going to keep trying."); - } - }); - - if (options.count("es-objects-elasticsearch-url")) { my->_es_objects_elasticsearch_url = options["es-objects-elasticsearch-url"].as(); } @@ -372,6 +657,30 @@ void es_objects_plugin::plugin_initialize(const boost::program_options::variable if (options.count("es-objects-asset-bitasset")) { my->_es_objects_asset_bitasset = options["es-objects-asset-bitasset"].as(); } + if (options.count("es-objects-account-role")) { + my->_es_objects_balances = options["es-objects-account-role"].as(); + } + if (options.count("es-objects-committee-member")) { + my->_es_objects_balances = options["es-objects-committee-member"].as(); + } + if (options.count("es-objects-nft")) { + my->_es_objects_balances = options["es-objects-nft"].as(); + } + if (options.count("es-objects-son")) { + my->_es_objects_balances = options["es-objects-son"].as(); + } + if (options.count("es-objects-transaction")) { + my->_es_objects_balances = options["es-objects-transaction"].as(); + } + if (options.count("es-objects-vesting-balance")) { + my->_es_objects_balances = options["es-objects-vesting-balance"].as(); + } + if (options.count("es-objects-witness")) { + my->_es_objects_balances = options["es-objects-witness"].as(); + } + if (options.count("es-objects-worker")) { + my->_es_objects_balances = options["es-objects-worker"].as(); + } if (options.count("es-objects-index-prefix")) { my->_es_objects_index_prefix = options["es-objects-index-prefix"].as(); } @@ -381,6 +690,37 @@ void es_objects_plugin::plugin_initialize(const boost::program_options::variable if (options.count("es-objects-start-es-after-block")) { my->_es_objects_start_es_after_block = options["es-objects-start-es-after-block"].as(); } + + database().applied_block.connect([this](const signed_block &b) { + if(b.block_num() == 1 && my->_es_objects_start_es_after_block == 0) { + if (!my->genesis()) + FC_THROW_EXCEPTION(graphene::chain::plugin_exception, "Error populating genesis data."); + } + }); + database().new_objects.connect([this]( const vector& ids, + const flat_set& impacted_accounts ) { + if(!my->index_database(ids, "create")) + { + FC_THROW_EXCEPTION(graphene::chain::plugin_exception, + "Error creating object from ES database, we are going to keep trying."); + } + }); + database().changed_objects.connect([this]( const vector& ids, + const flat_set& impacted_accounts ) { + if(!my->index_database(ids, "update")) + { + FC_THROW_EXCEPTION(graphene::chain::plugin_exception, + "Error updating object from ES database, we are going to keep trying."); + } + }); + database().removed_objects.connect([this](const vector& ids, + const vector& objs, const flat_set& impacted_accounts) { + if(!my->index_database(ids, "delete")) + { + FC_THROW_EXCEPTION(graphene::chain::plugin_exception, + "Error deleting object from ES database, we are going to keep trying."); + } + }); } void es_objects_plugin::plugin_startup() @@ -396,4 +736,4 @@ void es_objects_plugin::plugin_startup() ilog("elasticsearch OBJECTS: plugin_startup() begin"); } -} } +} } \ No newline at end of file diff --git a/libraries/plugins/generate_genesis/CMakeLists.txt b/libraries/plugins/generate_genesis/CMakeLists.txt index 45ad5719..acc24202 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 graphene_chain graphene_app graphene_time ) +target_link_libraries( graphene_generate_genesis PRIVATE graphene_plugin ) target_include_directories( graphene_generate_genesis PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/generate_uia_sharedrop_genesis/CMakeLists.txt b/libraries/plugins/generate_uia_sharedrop_genesis/CMakeLists.txt index d2a50ab6..737e7614 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 graphene_chain graphene_app graphene_time ) +target_link_libraries( graphene_generate_uia_sharedrop_genesis PRIVATE graphene_plugin ) target_include_directories( graphene_generate_uia_sharedrop_genesis PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp deleted file mode 100644 index ef1ae04c..00000000 --- a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2018 Abit More, 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 grouped_orders { - -namespace detail -{ - -class grouped_orders_plugin_impl -{ - public: - grouped_orders_plugin_impl(grouped_orders_plugin& _plugin) - :_self( _plugin ) {} - virtual ~grouped_orders_plugin_impl(); - - graphene::chain::database& database() - { - return _self.database(); - } - - grouped_orders_plugin& _self; - flat_set _tracked_groups; -}; - -/** - * @brief This secondary index is used to track changes on limit order objects. - */ -class limit_order_group_index : public secondary_index -{ - public: - limit_order_group_index( const flat_set& groups ) : _tracked_groups( groups ) {}; - - virtual void object_inserted( 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; - - const flat_set& get_tracked_groups() const - { return _tracked_groups; } - - const map< limit_order_group_key, limit_order_group_data >& get_order_groups() const - { return _og_data; } - - private: - void remove_order( const limit_order_object& obj, bool remove_empty = true ); - - /** tracked groups */ - flat_set _tracked_groups; - - /** maps the group key to group data */ - map< limit_order_group_key, limit_order_group_data > _og_data; -}; - -void limit_order_group_index::object_inserted( const object& objct ) -{ try { - const limit_order_object& o = static_cast( objct ); - - auto& idx = _og_data; - - for( uint16_t group : get_tracked_groups() ) - { - auto create_ogo = [&]() { - idx[ limit_order_group_key( group, o.sell_price ) ] = limit_order_group_data( o.sell_price, o.for_sale ); - }; - // if idx is empty, insert this order - // Note: not capped - if( idx.empty() ) - { - create_ogo(); - continue; - } - - // cap the price - price capped_price = o.sell_price; - price max = o.sell_price.max(); - price min = o.sell_price.min(); - bool capped_max = false; - bool capped_min = false; - if( o.sell_price > max ) - { - capped_price = max; - capped_max = true; - } - else if( o.sell_price < min ) - { - capped_price = min; - capped_min = true; - } - // if idx is not empty, find the group that is next to this order - auto itr = idx.lower_bound( limit_order_group_key( group, capped_price ) ); - bool check_previous = false; - if( itr == idx.end() || itr->first.group != group - || itr->first.min_price.base.asset_id != o.sell_price.base.asset_id - || itr->first.min_price.quote.asset_id != o.sell_price.quote.asset_id ) - // not same market or group type - check_previous = true; - else // same market and group type - { - bool update_max = false; - if( capped_price > itr->second.max_price ) // implies itr->min_price <= itr->max_price < max - { - update_max = true; - price max_price = itr->first.min_price * ratio_type( GRAPHENE_100_PERCENT + group, GRAPHENE_100_PERCENT ); - // max_price should have been capped here - if( capped_price > max_price ) // new order is out of range - check_previous = true; - } - if( !check_previous ) // new order is within the range - { - if( capped_min && o.sell_price < itr->first.min_price ) - { // need to update itr->min_price here, if itr is below min, and new order is even lower - // TODO improve performance - limit_order_group_data data( itr->second.max_price, o.for_sale + itr->second.total_for_sale ); - idx.erase( itr ); - idx[ limit_order_group_key( group, o.sell_price ) ] = data; - } - else - { - if( update_max || ( capped_max && o.sell_price > itr->second.max_price ) ) - itr->second.max_price = o.sell_price; // store real price here, not capped - itr->second.total_for_sale += o.for_sale; - } - } - } - - if( check_previous ) - { - if( itr == idx.begin() ) // no previous - create_ogo(); - else - { - --itr; // should be valid - if( itr->first.group != group || itr->first.min_price.base.asset_id != o.sell_price.base.asset_id - || itr->first.min_price.quote.asset_id != o.sell_price.quote.asset_id ) - // not same market or group type - create_ogo(); - else // same market and group type - { - // due to lower_bound, always true: capped_price < itr->first.min_price, so no need to check again, - // if new order is in range of itr group, always need to update itr->first.min_price, unless - // o.sell_price is higher than max - price min_price = itr->second.max_price / ratio_type( GRAPHENE_100_PERCENT + group, GRAPHENE_100_PERCENT ); - // min_price should have been capped here - if( capped_price < min_price ) // new order is out of range - create_ogo(); - else if( capped_max && o.sell_price >= itr->first.min_price ) - { // itr is above max, and price of new order is even higher - if( o.sell_price > itr->second.max_price ) - itr->second.max_price = o.sell_price; - itr->second.total_for_sale += o.for_sale; - } - else - { // new order is within the range - // TODO improve performance - limit_order_group_data data( itr->second.max_price, o.for_sale + itr->second.total_for_sale ); - idx.erase( itr ); - idx[ limit_order_group_key( group, o.sell_price ) ] = data; - } - } - } - } - } -} FC_CAPTURE_AND_RETHROW( (objct) ); } - -void limit_order_group_index::object_removed( const object& objct ) -{ try { - const limit_order_object& o = static_cast( objct ); - remove_order( o ); -} FC_CAPTURE_AND_RETHROW( (objct) ); } - -void limit_order_group_index::about_to_modify( const object& objct ) -{ try { - const limit_order_object& o = static_cast( objct ); - remove_order( o, false ); -} FC_CAPTURE_AND_RETHROW( (objct) ); } - -void limit_order_group_index::object_modified( const object& objct ) -{ try { - object_inserted( objct ); -} FC_CAPTURE_AND_RETHROW( (objct) ); } - -void limit_order_group_index::remove_order( const limit_order_object& o, bool remove_empty ) -{ - auto& idx = _og_data; - - for( uint16_t group : get_tracked_groups() ) - { - // find the group that should contain this order - auto itr = idx.lower_bound( limit_order_group_key( group, o.sell_price ) ); - if( itr == idx.end() || itr->first.group != group - || itr->first.min_price.base.asset_id != o.sell_price.base.asset_id - || itr->first.min_price.quote.asset_id != o.sell_price.quote.asset_id - || itr->second.max_price < o.sell_price ) - { - // can not find corresponding group, should not happen - wlog( "can not find the order group containing order for removing (price dismatch): ${o}", ("o",o) ); - continue; - } - else // found - { - if( itr->second.total_for_sale < o.for_sale ) - // should not happen - wlog( "can not find the order group containing order for removing (amount dismatch): ${o}", ("o",o) ); - else if( !remove_empty || itr->second.total_for_sale > o.for_sale ) - itr->second.total_for_sale -= o.for_sale; - else - // it's the only order in the group and need to be removed - idx.erase( itr ); - } - } -} - -grouped_orders_plugin_impl::~grouped_orders_plugin_impl() -{} - -} // end namespace detail - - -grouped_orders_plugin::grouped_orders_plugin() : - my( new detail::grouped_orders_plugin_impl(*this) ) -{ -} - -grouped_orders_plugin::~grouped_orders_plugin() -{ -} - -std::string grouped_orders_plugin::plugin_name()const -{ - return "grouped_orders"; -} - -void grouped_orders_plugin::plugin_set_program_options( - boost::program_options::options_description& cli, - boost::program_options::options_description& cfg - ) -{ - cli.add_options() - ("tracked-groups", boost::program_options::value()->default_value("[10,100]"), // 0.1% and 1% - "Group orders by percentage increase on price. Specify a JSON array of numbers here, each number is a group, number 1 means 0.01%. ") - ; - cfg.add(cli); -} - -void grouped_orders_plugin::plugin_initialize(const boost::program_options::variables_map& options) -{ try { - - if( options.count( "tracked-groups" ) ) - { - const std::string& groups = options["tracked-groups"].as(); - my->_tracked_groups = fc::json::from_string(groups).as>( 2 ); - my->_tracked_groups.erase( 0 ); - } - else - my->_tracked_groups = fc::json::from_string("[10,100]").as>(2); - - database().add_secondary_index< primary_index, detail::limit_order_group_index >( my->_tracked_groups ); - -} FC_CAPTURE_AND_RETHROW() } - -void grouped_orders_plugin::plugin_startup() -{ -} - -const flat_set& grouped_orders_plugin::tracked_groups() const -{ - return my->_tracked_groups; -} - -const map< limit_order_group_key, limit_order_group_data >& grouped_orders_plugin::limit_order_groups() -{ - const auto& idx = database().get_index_type< limit_order_index >(); - const auto& pidx = dynamic_cast&>(idx); - const auto& logidx = pidx.get_secondary_index< detail::limit_order_group_index >(); - return logidx.get_order_groups(); -} - -} } diff --git a/libraries/plugins/market_history/CMakeLists.txt b/libraries/plugins/market_history/CMakeLists.txt index 47410d74..8100de28 100644 --- a/libraries/plugins/market_history/CMakeLists.txt +++ b/libraries/plugins/market_history/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_market_history market_history_plugin.cpp ) -target_link_libraries( graphene_market_history graphene_chain graphene_app ) +target_link_libraries( graphene_market_history PRIVATE graphene_plugin ) target_include_directories( graphene_market_history PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/peerplays_sidechain/CMakeLists.txt b/libraries/plugins/peerplays_sidechain/CMakeLists.txt index 3e37b6fe..3737ae61 100755 --- a/libraries/plugins/peerplays_sidechain/CMakeLists.txt +++ b/libraries/plugins/peerplays_sidechain/CMakeLists.txt @@ -36,7 +36,7 @@ endif() unset(ENABLE_PEERPLAYS_ASSET_DEPOSITS) unset(ENABLE_PEERPLAYS_ASSET_DEPOSITS CACHE) -target_link_libraries( peerplays_sidechain graphene_chain graphene_app fc zmq ) +target_link_libraries( peerplays_sidechain PRIVATE graphene_plugin zmq ) target_include_directories( peerplays_sidechain PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp index 07078147..2e71adb5 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace graphene { namespace peerplays_sidechain { namespace bitcoin { diff --git a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp index b4fde6dc..fac29f5a 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 diff --git a/libraries/plugins/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.cpp b/libraries/plugins/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.cpp index edb45c5b..afad2093 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.cpp @@ -1,4 +1,7 @@ #include + +#include + #include namespace graphene { namespace peerplays_sidechain { namespace bitcoin { diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index dcd5e401..abde7b51 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -138,8 +138,10 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt config_ready_son = (options.count("son-id") || options.count("son-ids")) && options.count("peerplays-private-key"); if (config_ready_son) { LOAD_VALUE_SET(options, "son-id", sons, chain::son_id_type) - if (options.count("son-ids")) - boost::insert(sons, fc::json::from_string(options.at("son-ids").as()).as>(5)); + if (options.count("son-ids")) { + vector v = fc::json::from_string(options.at("son-ids").as()).as>(5); + sons.insert(v.begin(), v.end()); + } config_ready_son = config_ready_son && !sons.empty(); #ifndef ENABLE_MULTIPLE_SONS diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp index 49c5f022..5ceab83a 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -283,6 +283,7 @@ void sidechain_net_handler::process_proposals() { int32_t op_idx_1 = -1; chain::operation op_obj_idx_1; + (void) op_idx_1; if (po->proposed_transaction.operations.size() >= 2) { op_idx_1 = po->proposed_transaction.operations[1].which(); diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index dc5e88af..65b00b19 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -1005,6 +1005,7 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) int32_t op_idx_1 = -1; chain::operation op_obj_idx_1; + (void) op_idx_1; if (po.proposed_transaction.operations.size() >= 2) { op_idx_1 = po.proposed_transaction.operations[1].which(); @@ -1107,8 +1108,8 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) std::string tx_txid = tx_json.get("result.txid"); uint32_t tx_confirmations = tx_json.get("result.confirmations"); std::string tx_address = ""; - int64_t tx_amount = -1; - int64_t tx_vout = -1; + uint64_t tx_amount = -1; + uint64_t tx_vout = -1; for (auto &input : tx_json.get_child("result.vout")) { std::string tx_vout_s = input.second.get("n"); @@ -1349,6 +1350,7 @@ void sidechain_net_handler_bitcoin::process_sidechain_addresses() { const auto &sidechain_addresses_by_sidechain_range = sidechain_addresses_by_sidechain_idx.equal_range(sidechain); std::for_each(sidechain_addresses_by_sidechain_range.first, sidechain_addresses_by_sidechain_range.second, [&](const sidechain_address_object &sao) { + bool retval = true; if (sao.expires == time_point_sec::maximum()) { auto usr_pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(sao.deposit_public_key))); @@ -1374,13 +1376,14 @@ void sidechain_net_handler_bitcoin::process_sidechain_addresses() { database.push_transaction(trx, database::validation_steps::skip_block_size_check); if (plugin.app().p2p_node()) plugin.app().p2p_node()->broadcast(net::trx_message(trx)); - return true; + retval = true; } catch (fc::exception &e) { elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what())); - return false; + retval = false; } } } + return retval; }); } @@ -1658,11 +1661,11 @@ std::string sidechain_net_handler_bitcoin::create_withdrawal_transaction(const s std::string pw_address = json.get("address"); std::string redeem_script = json.get("redeemScript"); - uint64_t fee_rate = bitcoin_client->estimatesmartfee(); - uint64_t min_fee_rate = 1000; + int64_t fee_rate = bitcoin_client->estimatesmartfee(); + int64_t min_fee_rate = 1000; fee_rate = std::max(fee_rate, min_fee_rate); - uint64_t total_amount = 0; + int64_t total_amount = 0; std::vector inputs = bitcoin_client->listunspent_by_address_and_amount(pw_address, 0); if (inputs.size() == 0) { diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp index ecf3cc00..1bbce500 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp @@ -131,6 +131,7 @@ void sidechain_net_handler_peerplays::process_sidechain_addresses() { const auto &sidechain_addresses_by_sidechain_range = sidechain_addresses_by_sidechain_idx.equal_range(sidechain); std::for_each(sidechain_addresses_by_sidechain_range.first, sidechain_addresses_by_sidechain_range.second, [&](const sidechain_address_object &sao) { + bool retval = true; if (sao.expires == time_point_sec::maximum()) { if (sao.deposit_address == "") { sidechain_address_update_operation op; @@ -150,13 +151,14 @@ void sidechain_net_handler_peerplays::process_sidechain_addresses() { database.push_transaction(trx, database::validation_steps::skip_block_size_check); if (plugin.app().p2p_node()) plugin.app().p2p_node()->broadcast(net::trx_message(trx)); - return true; + retval = true; } catch (fc::exception &e) { elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what())); - return false; + retval = false; } } } + return retval; }); return; } diff --git a/libraries/plugins/snapshot/CMakeLists.txt b/libraries/plugins/snapshot/CMakeLists.txt index 728740de..57fb1689 100644 --- a/libraries/plugins/snapshot/CMakeLists.txt +++ b/libraries/plugins/snapshot/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_snapshot snapshot.cpp ) -target_link_libraries( graphene_snapshot graphene_chain graphene_app ) +target_link_libraries( graphene_snapshot PRIVATE graphene_plugin ) target_include_directories( graphene_snapshot PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/witness/CMakeLists.txt b/libraries/plugins/witness/CMakeLists.txt index 95759bbf..a4272b2d 100644 --- a/libraries/plugins/witness/CMakeLists.txt +++ b/libraries/plugins/witness/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_witness witness.cpp ) -target_link_libraries( graphene_witness graphene_chain graphene_app ) +target_link_libraries( graphene_witness PRIVATE graphene_plugin ) target_include_directories( graphene_witness PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index 1e7a9d6e..d535ca3b 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -91,8 +91,10 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m ilog("witness plugin: plugin_initialize() begin"); _options = &options; LOAD_VALUE_SET(options, "witness-id", _witnesses, chain::witness_id_type) - if (options.count("witness-ids")) - boost::insert(_witnesses, fc::json::from_string(options.at("witness-ids").as()).as>( 5 )); + if (options.count("witness-ids")) { + vector v = fc::json::from_string(options.at("witness-ids").as()).as>( 5 ); + _witnesses.insert(v.begin(), v.end()); + } if( options.count("private-key") ) { diff --git a/libraries/wallet/CMakeLists.txt b/libraries/wallet/CMakeLists.txt index 8c9f8790..d3825810 100644 --- a/libraries/wallet/CMakeLists.txt +++ b/libraries/wallet/CMakeLists.txt @@ -23,7 +23,7 @@ else() endif() add_library( graphene_wallet wallet.cpp ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp ${HEADERS} ) -target_link_libraries( graphene_wallet PRIVATE graphene_app graphene_net graphene_chain graphene_utilities fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( graphene_wallet PRIVATE graphene_app ) target_include_directories( graphene_db PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) if(MSVC) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 4887f35b..498aa51a 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -62,13 +62,18 @@ struct brain_key_info public_key_type pub_key; }; +enum authority_type +{ + owner, + active +}; /** * Contains the confirmation receipt the sender must give the receiver and * the meta data about the receipt that helps the sender identify which receipt is * for the receiver and which is for the change address. */ -struct blind_confirmation +struct blind_confirmation { struct output { @@ -312,7 +317,7 @@ class wallet_api */ uint64_t get_account_count()const; /** Lists all accounts controlled by this wallet. - * This returns a list of the full account objects for all accounts whose private keys + * This returns a list of the full account objects for all accounts whose private keys * we possess. * @returns a list of account objects */ @@ -324,14 +329,14 @@ class wallet_api * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass * the last account name returned as the \c lowerbound for the next \c list_accounts() call. * - * @param lowerbound the name of the first account to return. If the named account does not exist, + * @param lowerbound the name of the first account to return. If the named account does not exist, * the list will start at the account that comes after \c lowerbound * @param limit the maximum number of accounts to return (max: 1000) * @returns a list of accounts mapping account names to account ids */ map list_accounts(const string& lowerbound, uint32_t limit); /** List the balances of an account. - * Each account can have multiple balances, one for each type of asset owned by that + * Each account can have multiple balances, one for each type of asset owned by that * account. The returned list will only contain assets for which the account has a * nonzero balance * @param id the name or id of the account whose balances you want @@ -339,7 +344,7 @@ class wallet_api */ vector list_account_balances(const string& id); /** Lists all assets registered on the blockchain. - * + * * To list all assets, pass the empty string \c "" for the lowerbound to start * at the beginning of the list, and iterate as necessary. * @@ -350,12 +355,12 @@ class wallet_api vector list_assets(const string& lowerbound, uint32_t limit)const; /** Returns assets count registered on the blockchain. - * + * * @returns assets count */ uint64_t get_asset_count()const; - - + + vector get_lotteries( asset_id_type stop = asset_id_type(), unsigned limit = 100, asset_id_type start = asset_id_type() )const; @@ -391,7 +396,7 @@ class wallet_api vector get_limit_orders(string a, string b, uint32_t limit)const; vector get_call_orders(string a, uint32_t limit)const; vector get_settle_orders(string a, uint32_t limit)const; - + /** Returns the block chain's slowly-changing settings. * This object contains all of the properties of the blockchain that are fixed * or that change only once per maintenance interval (daily) such as the @@ -447,8 +452,8 @@ class wallet_api * Returns the blockchain object corresponding to the given id. * * This generic function can be used to retrieve any object from the blockchain - * that is assigned an ID. Certain types of objects have specialized convenience - * functions to return their objects -- e.g., assets have \c get_asset(), accounts + * that is assigned an ID. Certain types of objects have specialized convenience + * functions to return their objects -- e.g., assets have \c get_asset(), accounts * have \c get_account(), but this function will work for any object. * * @param id the id of the object to return @@ -456,7 +461,7 @@ class wallet_api */ variant get_object(object_id_type id) const; - /** Returns the current wallet filename. + /** Returns the current wallet filename. * * This is the filename that will be used when automatically saving the wallet. * @@ -532,21 +537,21 @@ class wallet_api * @ingroup Wallet Management */ bool is_new()const; - - /** Checks whether the wallet is locked (is unable to use its private keys). + + /** Checks whether the wallet is locked (is unable to use its private keys). * * This state can be changed by calling \c lock() or \c unlock(). * @return true if the wallet is locked * @ingroup Wallet Management */ bool is_locked()const; - + /** Locks the wallet immediately. * @ingroup Wallet Management */ void lock(); - - /** Unlocks the wallet. + + /** Unlocks the wallet. * * The wallet remain unlocked until the \c lock is called * or the program exits. @@ -554,7 +559,7 @@ class wallet_api * @ingroup Wallet Management */ void unlock(string password); - + /** Sets a new password on the wallet. * * The wallet must be either 'new' or 'unlocked' to @@ -567,7 +572,7 @@ class wallet_api * * The keys are printed in WIF format. You can import these keys into another wallet * using \c import_key() - * @returns a map containing the private keys, indexed by their public key + * @returns a map containing the private keys, indexed by their public key */ map dump_private_keys(); @@ -602,13 +607,13 @@ class wallet_api bool load_wallet_file(string wallet_filename = ""); /** Quitting from Peerplays wallet. - * + * * The current wallet will be closed. */ void quit(); /** Saves the current wallet to the given filename. - * + * * @warning This does not change the wallet filename that will be used for future * writes, so think of this function as 'Save a Copy As...' instead of * 'Save As...'. Use \c set_wallet_filename() to make the filename @@ -677,7 +682,7 @@ class wallet_api /** Imports the private key for an existing account. * * The private key must match either an owner key or an active key for the - * named account. + * named account. * * @see dump_private_keys() * @@ -740,6 +745,41 @@ class wallet_api uint32_t referrer_percent, bool broadcast = false); + /** Updates account public keys + * + * @param name the name of the existing account + * @param old_owner the owner key for the named account to be replaced + * @param new_owner the owner key for the named account to be set as new + * @param old_active the active key for the named account to be replaced + * @param new_active the active key for the named account to be set as new + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction updating account public keys + */ + signed_transaction update_account_keys(string name, + public_key_type old_owner, + public_key_type new_owner, + public_key_type old_active, + public_key_type new_active, + bool broadcast = false); + + /** + * This method updates the key of an authority for an exisiting account. + * Warning: You can create impossible authorities using this method. The method + * will fail if you create an impossible owner authority, but will allow impossible + * active and posting authorities. + * + * @param account_name The name of the account whose authority you wish to update + * @param type The authority type. e.g. owner or active + * @param key The public key to add to the authority + * @param weight The weight the key should have in the authority. A weight of 0 indicates the removal of the key. + * @param broadcast true if you wish to broadcast the transaction. + */ + signed_transaction update_account_auth_key(string account_name, + authority_type type, + public_key_type key, + weight_type weight, + bool broadcast); + /** * Upgrades an account to prime status. * This makes the account holder a 'lifetime member'. @@ -780,7 +820,7 @@ class wallet_api * @param to the name or id of the account receiving the funds * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) * @param asset_symbol the symbol or id of the asset to send - * @param memo a memo to attach to the transaction. The memo will be encrypted in the + * @param memo a memo to attach to the transaction. The memo will be encrypted in the * transaction and readable for the receiver. There is no length limit * other than the limit imposed by maximum transaction size, but transaction * increase with transaction size @@ -855,7 +895,7 @@ class wallet_api * who sent it. * * @param opt_from - if not empty and the sender is a unknown public key, then the unknown public key will be given the label opt_from - * @param confirmation_receipt - a base58 encoded stealth confirmation + * @param confirmation_receipt - a base58 encoded stealth confirmation */ blind_receipt receive_blind_transfer( string confirmation_receipt, string opt_from, string opt_memo ); @@ -863,18 +903,18 @@ class wallet_api * Transfers a public balance from @from to one or more blinded balances using a * stealth transfer. */ - blind_confirmation transfer_to_blind( string from_account_id_or_name, + blind_confirmation transfer_to_blind( string from_account_id_or_name, string asset_symbol, /** map from key or label to amount */ - vector> to_amounts, + vector> to_amounts, bool broadcast = false ); /** * Transfers funds from a set of blinded balances to a public account balance. */ - blind_confirmation transfer_from_blind( + blind_confirmation transfer_from_blind( string from_blind_account_key_or_label, - string to_account_id_or_name, + string to_account_id_or_name, string amount, string asset_symbol, bool broadcast = false ); @@ -890,14 +930,14 @@ class wallet_api /** Place a limit order attempting to sell one asset for another. * - * Buying and selling are the same operation on Graphene; if you want to buy BTS + * Buying and selling are the same operation on Graphene; if you want to buy BTS * with USD, you should sell USD for BTS. * * The blockchain will attempt to sell the \c symbol_to_sell for as - * much \c symbol_to_receive as possible, as long as the price is at - * least \c min_to_receive / \c amount_to_sell. + * much \c symbol_to_receive as possible, as long as the price is at + * least \c min_to_receive / \c amount_to_sell. * - * In addition to the transaction fees, market fees will apply as specified + * In addition to the transaction fees, market fees will apply as specified * by the issuer of both the selling asset and the receiving asset as * a percentage of the amount exchanged. * @@ -910,16 +950,16 @@ class wallet_api * * @todo Allow order expiration to be set here. Document default/max expiration time * - * @param seller_account the account providing the asset being sold, and which will + * @param seller_account the account providing the asset being sold, and which will * receive the proceeds of the sale. * @param amount_to_sell the amount of the asset being sold to sell (in nominal units) * @param symbol_to_sell the name or id of the asset to sell * @param min_to_receive the minimum amount you are willing to receive in return for * selling the entire amount_to_sell * @param symbol_to_receive the name or id of the asset you wish to receive - * @param timeout_sec if the order does not fill immediately, this is the length of - * time the order will remain on the order books before it is - * cancelled and the un-spent funds are returned to the seller's + * @param timeout_sec if the order does not fill immediately, this is the length of + * time the order will remain on the order books before it is + * cancelled and the un-spent funds are returned to the seller's * account * @param fill_or_kill if true, the order will only be included in the blockchain * if it is filled immediately; if false, an open order will be @@ -936,12 +976,12 @@ class wallet_api uint32_t timeout_sec = 0, bool fill_or_kill = false, bool broadcast = false); - + /** Place a limit order attempting to sell one asset for another. - * + * * This API call abstracts away some of the details of the sell_asset call to be more * user friendly. All orders placed with sell never timeout and will not be killed if they - * cannot be filled immediately. If you wish for one of these parameters to be different, + * cannot be filled immediately. If you wish for one of these parameters to be different, * then sell_asset should be used instead. * * @param seller_account the account providing the asset being sold, and which will @@ -951,7 +991,7 @@ class wallet_api * @param rate The rate in base:quote at which you want to sell. * @param amount The amount of base you want to sell. * @param broadcast true to broadcast the transaction on the network. - * @returns The signed transaction selling the funds. + * @returns The signed transaction selling the funds. */ signed_transaction sell( string seller_account, string base, @@ -959,7 +999,7 @@ class wallet_api double rate, double amount, bool broadcast ); - + /** Place a limit order attempting to buy one asset with another. * * This API call abstracts away some of the details of the sell_asset call to be more @@ -1014,14 +1054,14 @@ class wallet_api * Right now this function is difficult to use because you must provide raw JSON data * structures for the options objects, and those include prices and asset ids. * - * @param issuer the name or id of the account who will pay the fee and become the + * @param issuer the name or id of the account who will pay the fee and become the * issuer of the new asset. This can be updated later * @param symbol the ticker symbol of the new asset * @param precision the number of digits of precision to the right of the decimal point, * must be less than or equal to 12 * @param common asset options required for all new assets. - * Note that core_exchange_rate technically needs to store the asset ID of - * this new asset. Since this ID is not known at the time this operation is + * Note that core_exchange_rate technically needs to store the asset ID of + * this new asset. Since this ID is not known at the time this operation is * created, create this price as though the new asset has instance ID 1, and * the chain will overwrite it with the new asset's ID. * @param bitasset_opts options specific to BitAssets. This may be null unless the @@ -1041,7 +1081,7 @@ class wallet_api asset_options common, lottery_asset_options lottery_opts, bool broadcast = false); - + signed_transaction buy_ticket( asset_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy ); /** Issue new shares of an asset. @@ -1059,8 +1099,8 @@ class wallet_api bool broadcast = false); /** Update the core options on an asset. - * There are a number of options which all assets in the network use. These options are - * enumerated in the asset_object::asset_options struct. This command is used to update + * There are a number of options which all assets in the network use. These options are + * enumerated in the asset_object::asset_options struct. This command is used to update * these options for an existing asset. * * @note This operation cannot be used to update BitAsset-specific options. For these options, @@ -1124,7 +1164,7 @@ class wallet_api signed_transaction update_asset_feed_producers(string symbol, flat_set new_feed_producers, bool broadcast = false); - + /** Publishes a price feed for the named asset. * * Price feed providers use this command to publish their price feeds for market-issued assets. A price feed is @@ -1152,7 +1192,7 @@ class wallet_api /** Pay into the fee pool for the given asset. * - * User-issued assets can optionally have a pool of the core asset which is + * User-issued assets can optionally have a pool of the core asset which is * automatically used to pay transaction fees for any transaction using that * asset (using the asset's core exchange rate). * @@ -1193,7 +1233,7 @@ class wallet_api * used as backing for other bitassets, those bitassets will be force settled at their current * feed price. * - * @note this operation is used only by the asset issuer, \c settle_asset() may be used by + * @note this operation is used only by the asset issuer, \c settle_asset() may be used by * any user owning the asset * * @param symbol the name or id of the asset to force settlement on @@ -1261,7 +1301,7 @@ class wallet_api * @returns the signed transaction registering a committee_member */ signed_transaction create_committee_member(string owner_account, - string url, + string url, bool broadcast = false); /** Lists all witnesses registered in the blockchain. @@ -1272,7 +1312,7 @@ class wallet_api * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass * the last witness name returned as the \c lowerbound for the next \c list_witnesss() call. * - * @param lowerbound the name of the first witness to return. If the named witness does not exist, + * @param lowerbound the name of the first witness to return. If the named witness does not exist, * the list will start at the witness that comes after \c lowerbound * @param limit the maximum number of witnesss to return (max: 1000) * @returns a list of witnesss mapping witness names to witness ids @@ -1287,7 +1327,7 @@ class wallet_api * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass * the last committee_member name returned as the \c lowerbound for the next \c list_committee_members() call. * - * @param lowerbound the name of the first committee_member to return. If the named committee_member does not exist, + * @param lowerbound the name of the first committee_member to return. If the named committee_member does not exist, * the list will start at the committee_member that comes after \c lowerbound * @param limit the maximum number of committee_members to return (max: 1000) * @returns a list of committee_members mapping committee_member names to committee_member ids @@ -1607,7 +1647,7 @@ class wallet_api /** Vote for a given committee_member. * - * An account can publish a list of all committee_memberes they approve of. This + * An account can publish a list of all committee_memberes they approve of. This * command allows you to add or remove committee_memberes from this list. * Each account's vote is weighted according to the number of shares of the * core asset owned by that account at the time the votes are tallied. @@ -1617,7 +1657,7 @@ class wallet_api * * @param voting_account the name or id of the account who is voting with their shares * @param committee_member the name or id of the committee_member' owner account - * @param approve true if you wish to vote in favor of that committee_member, false to + * @param approve true if you wish to vote in favor of that committee_member, false to * remove your vote in favor of that committee_member * @param broadcast true if you wish to broadcast the transaction * @return the signed transaction changing your vote for the given committee_member @@ -1684,7 +1724,7 @@ class wallet_api /** Vote for a given witness. * - * An account can publish a list of all witnesses they approve of. This + * An account can publish a list of all witnesses they approve of. This * command allows you to add or remove witnesses from this list. * Each account's vote is weighted according to the number of shares of the * core asset owned by that account at the time the votes are tallied. @@ -1694,7 +1734,7 @@ class wallet_api * * @param voting_account the name or id of the account who is voting with their shares * @param witness the name or id of the witness' owner account - * @param approve true if you wish to vote in favor of that witness, false to + * @param approve true if you wish to vote in favor of that witness, false to * remove your vote in favor of that witness * @param broadcast true if you wish to broadcast the transaction * @return the signed transaction changing your vote for the given witness @@ -1706,12 +1746,12 @@ class wallet_api /** Change your witness votes. * - * An account can publish a list of all witnesses they approve of. + * An account can publish a list of all witnesses they approve of. * Each account's vote is weighted according to the number of shares of the * core asset owned by that account at the time the votes are tallied. - * This command allows you to add or remove one or more witnesses from this list + * This command allows you to add or remove one or more witnesses from this list * in one call. When you are changing your vote on several witnesses, this - * may be easier than multiple `vote_for_witness` and + * may be easier than multiple `vote_for_witness` and * `set_desired_witness_and_committee_member_count` calls. * * @note you cannot vote against a witness, you can only vote for the witness @@ -1726,7 +1766,7 @@ class wallet_api * you currently approve). This list can be empty. * @param desired_number_of_witnesses the number of witnesses you believe the network * should have. You must vote for at least this many - * witnesses. You can set this to 0 to abstain from + * witnesses. You can set this to 0 to abstain from * voting on the number of witnesses. * @param broadcast true if you wish to broadcast the transaction * @return the signed transaction changing your vote for the given witnesses @@ -1757,23 +1797,23 @@ class wallet_api signed_transaction set_voting_proxy(string account_to_modify, optional voting_account, bool broadcast = false); - + /** Set your vote for the number of witnesses and committee_members in the system. * - * Each account can voice their opinion on how many committee_members and how many + * Each account can voice their opinion on how many committee_members and how many * witnesses there should be in the active committee_member/active witness list. These * are independent of each other. You must vote your approval of at least as many * committee_members or witnesses as you claim there should be (you can't say that there should - * be 20 committee_members but only vote for 10). + * be 20 committee_members but only vote for 10). * - * There are maximum values for each set in the blockchain parameters (currently + * There are maximum values for each set in the blockchain parameters (currently * defaulting to 1001). * * This setting can be changed at any time. If your account has a voting proxy * set, your preferences will be ignored. * * @param account_to_modify the name or id of the account to update - * @param number_of_committee_members the number + * @param number_of_committee_members the number * * @param broadcast true if you wish to broadcast the transaction * @return the signed transaction changing your vote proxy settings @@ -1826,16 +1866,16 @@ class wallet_api /** Returns an uninitialized object representing a given blockchain operation. * - * This returns a default-initialized object of the given type; it can be used + * This returns a default-initialized object of the given type; it can be used * during early development of the wallet when we don't yet have custom commands for - * creating all of the operations the blockchain supports. + * creating all of the operations the blockchain supports. * * Any operation the blockchain supports can be created using the transaction builder's - * \c add_operation_to_builder_transaction() , but to do that from the CLI you need to + * \c add_operation_to_builder_transaction() , but to do that from the CLI you need to * know what the JSON form of the operation looks like. This will give you a template * you can fill in. It's better than nothing. - * - * @param operation_type the type of operation to return, must be one of the + * + * @param operation_type the type of operation to return, must be one of the * operations defined in `graphene/chain/operations.hpp` * (e.g., "global_parameters_update_operation") * @return a default-constructed operation of the given type @@ -1860,7 +1900,7 @@ class wallet_api bool broadcast = false); /** Propose a fee change. - * + * * @param proposing_account The account paying the fee to propose the tx * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. * @param changed_values Map of operation type to new fee. Operations may be specified by name or ID. @@ -1902,7 +1942,33 @@ class wallet_api const approval_delta& delta, bool broadcast /* = false */ ); - + + /** Get random numbers + * @brief Returns the random number + * @param minimum Lower bound of segment containing random number + * @param maximum Upper bound of segment containing random number + * @param selections Number of random numbers to return + * @param duplicates Allow duplicated numbers + * @param broadcast true if you wish to broadcast the transaction + * @return the signed version of the transaction + * @return Vector containing random numbers from segment [minimum, maximum) + */ + vector get_random_number_ex(string account, + uint64_t minimum, + uint64_t maximum, + uint64_t selections, + bool duplicates, + bool broadcast); + + /** Get random number + * @brief Returns the random number + * @param bound Upper bound of segment containing random number + * @return Random number from segment [0, bound) + */ + uint64_t get_random_number(string account, + uint64_t bound, + bool broadcast); + order_book get_order_book( const string& base, const string& quote, unsigned limit = 50); asset get_total_matched_bet_amount_for_betting_market_group(betting_market_group_id_type group_id); @@ -1941,7 +2007,7 @@ class wallet_api sport_id_type sport_id, fc::optional name, bool broadcast = false); - + signed_transaction propose_delete_sport( const string& proposing_account, fc::time_point_sec expiration_time, @@ -1968,7 +2034,7 @@ class wallet_api fc::time_point_sec expiration_time, event_group_id_type event_group, bool broadcast = false); - + signed_transaction propose_create_event( const string& proposing_account, fc::time_point_sec expiration_time, @@ -2039,7 +2105,7 @@ class wallet_api fc::optional payout_condition, bool broadcast = false); - /** Place a bet + /** Place a bet * @param bettor the account placing the bet * @param betting_market_id the market on which to bet * @param back_or_lay back or lay @@ -2115,7 +2181,7 @@ class wallet_api tournament_state state); /** Get specific information about a tournament - * @param tournament_id the ID of the tournament + * @param tournament_id the ID of the tournament */ tournament_object get_tournament(tournament_id_type id); @@ -2161,6 +2227,7 @@ class wallet_api vector get_custom_account_authorities_by_permission_id(custom_permission_id_type permission_id) const; vector get_custom_account_authorities_by_permission_name(string owner, string permission_name) const; vector get_active_custom_account_authorities_by_operation(string owner, int operation_type) const; + ///////// // NFT // ///////// @@ -2186,6 +2253,8 @@ class wallet_api bool is_transferable, bool is_sellable, optional role_id, + optional max_supply, + optional lottery_options, bool broadcast); /** @@ -2323,6 +2392,7 @@ class wallet_api * @return Returns vector of NFT objects, empty vector if none */ vector nft_get_all_tokens() const; + signed_transaction nft_lottery_buy_ticket( nft_metadata_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy, bool broadcast ); signed_transaction create_offer(set item_ids, string issuer_accound_id_or_name, @@ -2433,6 +2503,8 @@ FC_REFLECT( graphene::wallet::brain_key_info, (pub_key) ) +FC_REFLECT_ENUM( graphene::wallet::authority_type, (owner)(active) ) + FC_REFLECT( graphene::wallet::exported_account_keys, (account_name)(encrypted_private_keys)(public_keys) ) FC_REFLECT( graphene::wallet::exported_keys, (password_checksum)(account_keys) ) @@ -2461,7 +2533,7 @@ FC_REFLECT_DERIVED( graphene::wallet::signed_block_with_info, (graphene::chain:: FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object), (allowed_withdraw)(allowed_withdraw_time) ) -FC_REFLECT( graphene::wallet::operation_detail, +FC_REFLECT( graphene::wallet::operation_detail, (memo)(description)(op) ) FC_API( graphene::wallet::wallet_api, @@ -2496,6 +2568,8 @@ FC_API( graphene::wallet::wallet_api, (derive_owner_keys_from_brain_key) (get_private_key_from_password) (register_account) + (update_account_keys) + (update_account_auth_key) (upgrade_account) (create_account_with_brain_key) (sell_asset) @@ -2590,6 +2664,8 @@ FC_API( graphene::wallet::wallet_api, (propose_fee_change) (propose_dividend_asset_update) (approve_proposal) + (get_random_number_ex) + (get_random_number) (dbg_make_uia) (dbg_make_mia) (dbg_push_blocks) @@ -2653,6 +2729,7 @@ FC_API( graphene::wallet::wallet_api, (nft_get_approved) (nft_is_approved_for_all) (nft_get_all_tokens) + (nft_lottery_buy_ticket) (create_offer) (create_bid) (cancel_offer) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 98dc122c..2f89c155 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -615,7 +615,7 @@ public: throw fc::canceled_exception(); } - + bool copy_wallet_file( string destination_filename ) { fc::path src_path = get_wallet_filename(); @@ -909,7 +909,7 @@ public: const rock_paper_scissors_game_details& rps_details = game_obj.game_details.get(); for (unsigned i = 0; i < 2; ++i) { - if (rps_details.commit_moves.at(i) && + if (rps_details.commit_moves.at(i) && !rps_details.reveal_moves.at(i)) // if this player has committed but not revealed { const account_id_type& account_id = game_obj.players[i]; @@ -929,7 +929,7 @@ public: if (iter != _wallet.committed_game_moves.end()) { const rock_paper_scissors_throw_reveal& reveal = iter->second; - + game_move_operation move_operation; move_operation.game_id = game_obj.id; move_operation.player_account_id = account_id; @@ -972,7 +972,7 @@ public: } } FC_RETHROW_EXCEPTIONS(warn, "") } - // Cache all matches in the tournament, which will also register us for + // Cache all matches in the tournament, which will also register us for // updates on those matches void monitor_matches_in_tournament(const tournament_object& tournament_obj) { try { @@ -1129,8 +1129,8 @@ public: dlog( "validated successfully tmp wallet file ${fn}", ("fn", tmp_wallet_filename) ); fc::rename( tmp_wallet_filename, wallet_filename ); dlog( "renamed successfully tmp wallet file ${fn}", ("fn", tmp_wallet_filename) ); - } - else + } + else { FC_THROW("tmp wallet file cannot be validated ${fn}", ("fn", tmp_wallet_filename) ); } @@ -1335,6 +1335,102 @@ public: } FC_CAPTURE_AND_RETHROW( (name)(owner)(active)(registrar_account)(referrer_account)(referrer_percent)(broadcast) ) } + signed_transaction update_account_keys(string name, + public_key_type old_owner, + public_key_type new_owner, + public_key_type old_active, + public_key_type new_active, + bool broadcast) + { try { + FC_ASSERT( !self.is_locked() ); + account_object account_obj = get_account(name); + + authority owner = account_obj.owner; + owner.key_auths[new_owner] = owner.key_auths[old_owner]; + owner.key_auths.erase(old_owner); + + authority active = account_obj.active; + active.key_auths[new_active] = active.key_auths[old_active]; + active.key_auths.erase(old_active); + + signed_transaction tx; + account_update_operation op; + + op.account = account_obj.get_id(); + op.owner = owner; + op.active = active; + + ilog("account_update_operation: ${op}", ("op", op)); + + tx.operations = {op}; + set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees ); + tx.validate(); + + return sign_transaction( tx, broadcast ); + } FC_CAPTURE_AND_RETHROW( (name) ) } + + + signed_transaction update_account_auth_key(string account_name, + authority_type type, + public_key_type key, + weight_type weight, + bool broadcast) + { + FC_ASSERT( !is_locked() ); + account_object account_obj = get_account(account_name); + + account_update_operation op; + op.account = account_obj.get_id(); + + authority new_auth; + + switch( type ) + { + case( owner ): + new_auth = account_obj.owner; + break; + case( active ): + new_auth = account_obj.active; + break; + } + + if( weight == 0 ) // Remove the key + { + new_auth.key_auths.erase( key ); + } + else + { + new_auth.add_authority( key, weight ); + } + + if( new_auth.is_impossible() ) + { + if ( type == owner ) + { + FC_ASSERT( false, "Owner authority change would render account irrecoverable." ); + } + + wlog( "Authority is now impossible." ); + } + + switch( type ) + { + case( owner ): + op.owner = new_auth; + break; + case( active ): + op.active = new_auth; + break; + } + + signed_transaction tx; + tx.operations.push_back(op); + set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees ); + tx.validate(); + + return sign_transaction( tx, broadcast ); + } + signed_transaction upgrade_account(string name, bool broadcast) { try { FC_ASSERT( !self.is_locked() ); @@ -1529,7 +1625,7 @@ public: return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (issuer)(symbol)(common)(broadcast) ) } - + signed_transaction buy_ticket( asset_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy ) { try { auto asset_obj = get_asset( lottery ); @@ -1540,7 +1636,7 @@ public: top.buyer = buyer; top.tickets_to_buy = tickets_to_buy; top.amount = asset( asset_obj.lottery_options->ticket_price.amount * tickets_to_buy, asset_obj.lottery_options->ticket_price.asset_id ); - + signed_transaction tx; tx.operations.push_back( top ); set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); @@ -1548,8 +1644,8 @@ public: return sign_transaction( tx, true ); } FC_CAPTURE_AND_RETHROW( (lottery)(tickets_to_buy) ) } - - + + signed_transaction update_asset(string symbol, optional new_issuer, asset_options new_options, @@ -2360,13 +2456,13 @@ public: fc::optional vbid = maybe_id(witness_name); if( !vbid ) { - if (is_witness(witness_name)) + if (is_witness(witness_name)) { witness_object wit = get_witness( witness_name ); FC_ASSERT( wit.pay_vb, "Account ${account} has no core Token ${TOKEN} vested and thus its not allowed to withdraw.", ("account", witness_name)("TOKEN", GRAPHENE_SYMBOL)); vbid = wit.pay_vb; } - else + else FC_THROW("Account ${account} has no core Token ${TOKEN} vested and thus its not allowed to withdraw.", ("account", witness_name)("TOKEN", GRAPHENE_SYMBOL)); } @@ -2409,14 +2505,14 @@ public: if( !vbid ) { vbos = _remote_db->get_vesting_balances( account_name ); - if( vbos.size() == 0 ) + if( vbos.size() == 0 ) FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); } - //whether it is a witness or user, keep it in a container and iterate over to process all vesting balances and types + //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) ); - + for (const vesting_balance_object& vesting_balance_obj: vbos) { if(vesting_balance_obj.balance_type == vesting_balance_type::gpos) { @@ -2446,7 +2542,7 @@ public: bool broadcast /* = false */) { try { std::vector vbo_info = get_vesting_balances(voting_account); - + time_point_sec now = time_point::now(); if(now >= HARDFORK_GPOS_TIME) //can be removed after GPOS HARDFORK time pass { @@ -2473,7 +2569,7 @@ public: const auto vesting_subperiod = _remote_db->get_global_properties().parameters.gpos_subperiod(); const auto gpos_start_time = fc::time_point_sec(_remote_db->get_global_properties().parameters.gpos_period_start()); const auto subperiod_start_time = gpos_start_time.sec_since_epoch() + (gpos_info.current_subperiod - 1) * vesting_subperiod; - + if (!insert_result.second && (gpos_info.last_voted_time.sec_since_epoch() >= subperiod_start_time)) FC_THROW("Account ${account} was already voting for committee_member ${committee_member} in the current GPOS sub-period", ("account", voting_account)("committee_member", committee_member)); else @@ -2599,7 +2695,7 @@ public: bool broadcast /* = false */) { try { std::vector vbo_info = get_vesting_balances(voting_account); - + time_point_sec now = time_point::now(); if(now >= HARDFORK_GPOS_TIME) //can be removed after GPOS HARDFORK time pass { @@ -2610,7 +2706,7 @@ public: } account_object voting_account_object = get_account(voting_account); - + fc::optional witness_obj = _remote_db->get_witness_by_account(witness); if (!witness_obj) FC_THROW("Account ${witness} is not registered as a witness", ("witness", witness)); @@ -2626,7 +2722,7 @@ public: const auto vesting_subperiod = _remote_db->get_global_properties().parameters.gpos_subperiod(); const auto gpos_start_time = fc::time_point_sec(_remote_db->get_global_properties().parameters.gpos_period_start()); const auto subperiod_start_time = gpos_start_time.sec_since_epoch() + (gpos_info.current_subperiod - 1) * vesting_subperiod; - + if (!insert_result.second && (gpos_info.last_voted_time.sec_since_epoch() >= subperiod_start_time)) FC_THROW("Account ${account} was already voting for witness ${witness} in the current GPOS sub-period", ("account", voting_account)("witness", witness)); else @@ -2644,7 +2740,7 @@ public: if (!votes_removed) FC_THROW("Account ${account} has not voted for witness ${witness}", ("account", voting_account)("witness", witness)); } - + account_update_operation account_update_op; account_update_op.account = voting_account_object.id; account_update_op.new_options = voting_account_object.options; @@ -3253,7 +3349,7 @@ public: { unsigned row_offset = (1 << round) - 1; unsigned row_vertical_spacing = 1 << (round + 1); - if (row >= row_offset && + if (row >= row_offset && (row - row_offset) % row_vertical_spacing == 0) { unsigned player_number_in_round = (row - row_offset) / row_vertical_spacing; @@ -3267,7 +3363,7 @@ public: if (round == num_rounds) { match_object match = get_object(tournament_details.matches[num_matches - 1]); - if (match.get_state() == match_state::match_complete && + if (match.get_state() == match_state::match_complete && !match.match_winners.empty()) { assert(match.match_winners.size() == 1); @@ -3723,6 +3819,38 @@ public: return _remote_db->get_active_custom_account_authorities_by_operation(get_account(owner).id, operation_type); } + vector get_random_number_ex(string account, + uint64_t minimum, + uint64_t maximum, + uint64_t selections, + bool duplicates, + bool broadcast) + { + + vector v = _remote_db->get_random_number_ex(minimum, maximum, selections, duplicates); + + random_number_store_operation op; + op.account = get_account(account).id; + op.random_number = v; + op.data = ""; + + signed_transaction trx; + trx.operations.push_back(op); + set_operation_fees( trx, _remote_db->get_global_properties().parameters.current_fees ); + trx.validate(); + sign_transaction( trx, broadcast ); + + return v; + } + + uint64_t get_random_number(string account, + uint64_t bound, + bool broadcast) + { + vector v = get_random_number_ex(account, 0, bound, 1, false, broadcast); + return v.at(0); + } + void dbg_make_uia(string creator, string symbol) { asset_options opts; @@ -4080,7 +4208,7 @@ std::string operation_printer::operator()(const bet_place_operation& op)const auto asset = wallet.get_asset(op.amount_to_bet.asset_id); auto bettor = wallet.get_account(op.bettor_id); - out << bettor.name << " placed a " << fc::json::to_string(op.back_or_lay) << " bet for " + out << bettor.name << " placed a " << fc::json::to_string(op.back_or_lay) << " bet for " << asset.amount_to_pretty_string(op.amount_to_bet) << " at odds " << ((double)op.backer_multiplier / GRAPHENE_BETTING_ODDS_PRECISION) << " on market " << fc::json::to_string(op.betting_market_id) << " fee: " << fee_asset.amount_to_pretty_string(op.fee); @@ -4223,7 +4351,7 @@ vector wallet_api::get_account_lotteries( account_id_type issuer, return my->_remote_db->get_account_lotteries( issuer, stop, limit, start ); } -asset wallet_api::get_lottery_balance( asset_id_type lottery_id )const +asset wallet_api::get_lottery_balance( asset_id_type lottery_id )const { return my->_remote_db->get_lottery_balance( lottery_id ); } @@ -4231,7 +4359,7 @@ asset wallet_api::get_lottery_balance( asset_id_type lottery_id )const vector wallet_api::get_account_history(string name, int limit) const { vector result; - + while (limit > 0) { bool skip_first_row = false; @@ -4282,9 +4410,9 @@ vector wallet_api::get_account_history(string name, int limit) vector wallet_api::get_relative_account_history(string name, uint32_t stop, int limit, uint32_t start)const { - + FC_ASSERT( start > 0 || limit <= 100 ); - + vector result; while( limit > 0 ) @@ -5256,6 +5384,23 @@ vector wallet_api::get_active_custom_account_authorities_by_operation return my->get_active_custom_account_authorities_by_operation(owner, operation_type); } +vector wallet_api::get_random_number_ex(string account, + uint64_t minimum, + uint64_t maximum, + uint64_t selections, + bool duplicates, + bool broadcast) +{ + return my->get_random_number_ex( account, minimum, maximum, selections, duplicates, broadcast ); +} + +uint64_t wallet_api::get_random_number(string account, + uint64_t bound, + bool broadcast) +{ + return my->get_random_number( account, bound, broadcast ); +} + global_property_object wallet_api::get_global_properties() const { return my->get_global_properties(); @@ -5536,6 +5681,25 @@ map wallet_api::dump_private_keys() return my->_keys; } +signed_transaction wallet_api::update_account_keys(string name, + public_key_type old_owner, + public_key_type new_owner, + public_key_type old_active, + public_key_type new_active, + bool broadcast ) +{ + return my->update_account_keys(name, old_owner, new_owner, old_active, new_active, broadcast); +} + +signed_transaction wallet_api::update_account_auth_key(string account_name, + authority_type type, + public_key_type key, + weight_type weight, + bool broadcast) +{ + return my->update_account_auth_key(account_name, type, key, weight, broadcast); +} + signed_transaction wallet_api::upgrade_account( string name, bool broadcast ) { return my->upgrade_account(name,broadcast); @@ -5561,8 +5725,15 @@ signed_transaction wallet_api::sell( string seller_account, double amount, bool broadcast ) { - return my->sell_asset( seller_account, std::to_string( amount ), base, - std::to_string( rate * amount ), quote, 0, false, broadcast ); + std::stringstream ss; + ss.str(std::string()); + ss << std::noshowpoint << amount; + std::string amount_to_sell = ss.str(); + ss.str(std::string()); + ss << std::noshowpoint << rate * amount; + std::string min_to_receive = ss.str(); + return my->sell_asset( seller_account, amount_to_sell, base, + min_to_receive, quote, 0, false, broadcast ); } signed_transaction wallet_api::buy( string buyer_account, @@ -5572,8 +5743,15 @@ signed_transaction wallet_api::buy( string buyer_account, double amount, bool broadcast ) { - return my->sell_asset( buyer_account, std::to_string( rate * amount ), quote, - std::to_string( amount ), base, 0, false, broadcast ); + std::stringstream ss; + ss.str(std::string()); + ss << std::noshowpoint << rate * amount; + std::string amount_to_sell = ss.str(); + ss.str(std::string()); + ss << std::noshowpoint << amount; + std::string min_to_receive = ss.str(); + return my->sell_asset( buyer_account, amount_to_sell, quote, + min_to_receive, base, 0, false, broadcast ); } signed_transaction wallet_api::borrow_asset(string seller_name, string amount_to_sell, @@ -6224,22 +6402,22 @@ signed_transaction wallet_api::propose_delete_sport( { FC_ASSERT( !is_locked() ); const chain_parameters& current_params = get_global_properties().parameters; - + sport_delete_operation sport_delete_op; sport_delete_op.sport_id = sport_id; - + proposal_create_operation prop_op; prop_op.expiration_time = expiration_time; prop_op.review_period_seconds = current_params.committee_proposal_review_period; prop_op.fee_paying_account = get_account(proposing_account).id; prop_op.proposed_ops.emplace_back( sport_delete_op ); current_params.current_fees->set_fee( prop_op.proposed_ops.back().op ); - + signed_transaction tx; tx.operations.push_back(prop_op); my->set_operation_fees(tx, current_params.current_fees); tx.validate(); - + return my->sign_transaction(tx, broadcast); } @@ -6302,7 +6480,7 @@ signed_transaction wallet_api::propose_update_event_group( return my->sign_transaction(tx, broadcast); } - + signed_transaction wallet_api::propose_delete_event_group( const string& proposing_account, fc::time_point_sec expiration_time, @@ -6311,22 +6489,22 @@ signed_transaction wallet_api::propose_delete_event_group( { FC_ASSERT( !is_locked() ); const chain_parameters& current_params = get_global_properties().parameters; - + event_group_delete_operation event_group_delete_op; event_group_delete_op.event_group_id = event_group; - + proposal_create_operation prop_op; prop_op.expiration_time = expiration_time; prop_op.review_period_seconds = current_params.committee_proposal_review_period; prop_op.fee_paying_account = get_account(proposing_account).id; prop_op.proposed_ops.emplace_back( event_group_delete_op ); current_params.current_fees->set_fee( prop_op.proposed_ops.back().op ); - + signed_transaction tx; tx.operations.push_back(prop_op); my->set_operation_fees(tx, current_params.current_fees); tx.validate(); - + return my->sign_transaction(tx, broadcast); } @@ -6711,10 +6889,10 @@ signed_transaction wallet_api::tournament_create( string creator, tournament_opt return my->sign_transaction( tx, broadcast ); } -signed_transaction wallet_api::tournament_join( string payer_account, - string player_account, - tournament_id_type tournament_id, - string buy_in_amount, +signed_transaction wallet_api::tournament_join( string payer_account, + string player_account, + tournament_id_type tournament_id, + string buy_in_amount, string buy_in_asset_symbol, bool broadcast ) { @@ -6796,7 +6974,7 @@ signed_transaction wallet_api::rps_throw(game_id_type game_id, 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::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)); @@ -6843,6 +7021,8 @@ signed_transaction wallet_api::nft_metadata_create(string owner_account_id_or_na bool is_transferable, bool is_sellable, optional role_id, + optional max_supply, + optional lottery_options, bool broadcast) { account_object owner_account = my->get_account(owner_account_id_or_name); @@ -6866,6 +7046,8 @@ signed_transaction wallet_api::nft_metadata_create(string owner_account_id_or_na op.is_transferable = is_transferable; op.is_sellable = is_sellable; op.account_role = role_id; + op.max_supply = max_supply; + op.lottery_options = lottery_options; signed_transaction trx; trx.operations.push_back(op); @@ -7049,6 +7231,21 @@ vector wallet_api::nft_get_all_tokens() const return my->_remote_db->nft_get_all_tokens(); } +signed_transaction wallet_api::nft_lottery_buy_ticket( nft_metadata_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy, bool broadcast ) +{ + nft_lottery_token_purchase_operation op; + op.lottery_id = lottery; + op.buyer = buyer; + op.tickets_to_buy = tickets_to_buy; + + signed_transaction trx; + trx.operations.push_back(op); + my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees ); + trx.validate(); + + return my->sign_transaction( trx, broadcast ); +} + signed_transaction wallet_api::create_offer(set item_ids, string issuer_accound_id_or_name, asset minimum_price, diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index ba73cdca..d9c82346 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory( build_helpers ) -if( BUILD_BITSHARES_PROGRAMS ) +if( BUILD_PEERPLAYS_PROGRAMS ) add_subdirectory( cli_wallet ) add_subdirectory( genesis_util ) add_subdirectory( witness_node ) @@ -7,4 +7,4 @@ if( BUILD_BITSHARES_PROGRAMS ) add_subdirectory( delayed_node ) add_subdirectory( js_operation_serializer ) add_subdirectory( size_checker ) -endif( BUILD_BITSHARES_PROGRAMS ) +endif( BUILD_PEERPLAYS_PROGRAMS ) diff --git a/programs/build_helpers/CMakeLists.txt b/programs/build_helpers/CMakeLists.txt index 7a625b25..e6e92455 100644 --- a/programs/build_helpers/CMakeLists.txt +++ b/programs/build_helpers/CMakeLists.txt @@ -5,7 +5,7 @@ if( UNIX AND NOT APPLE ) endif() # we only actually need Boost, but link against FC for now so we don't duplicate it. -target_link_libraries( cat-parts PRIVATE fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( cat-parts PRIVATE fc ${PLATFORM_SPECIFIC_LIBS} ) add_executable( member_enumerator member_enumerator.cpp ) if( UNIX AND NOT APPLE ) @@ -13,5 +13,5 @@ if( UNIX AND NOT APPLE ) endif() # we only actually need Boost, but link against FC for now so we don't duplicate it. -target_link_libraries( member_enumerator PRIVATE fc graphene_app graphene_net graphene_chain graphene_egenesis_brief graphene_utilities graphene_wallet ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( member_enumerator PRIVATE graphene_chain ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/programs/cli_wallet/CMakeLists.txt b/programs/cli_wallet/CMakeLists.txt index 140bdce3..31f697eb 100644 --- a/programs/cli_wallet/CMakeLists.txt +++ b/programs/cli_wallet/CMakeLists.txt @@ -10,7 +10,7 @@ if( GPERFTOOLS_FOUND ) endif() target_link_libraries( cli_wallet - PRIVATE graphene_app graphene_net graphene_chain graphene_egenesis_brief graphene_utilities graphene_wallet fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_egenesis_brief graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( main.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) diff --git a/programs/debug_node/CMakeLists.txt b/programs/debug_node/CMakeLists.txt index 232d265e..e39ea929 100644 --- a/programs/debug_node/CMakeLists.txt +++ b/programs/debug_node/CMakeLists.txt @@ -10,7 +10,7 @@ if( GPERFTOOLS_FOUND ) endif() target_link_libraries( debug_node - PRIVATE graphene_app graphene_account_history graphene_market_history graphene_witness graphene_debug_witness graphene_bookie graphene_chain graphene_egenesis_full fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_egenesis_full ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS debug_node diff --git a/programs/delayed_node/CMakeLists.txt b/programs/delayed_node/CMakeLists.txt index 4dbe2bbf..7e610ace 100644 --- a/programs/delayed_node/CMakeLists.txt +++ b/programs/delayed_node/CMakeLists.txt @@ -10,7 +10,7 @@ if( GPERFTOOLS_FOUND ) endif() target_link_libraries( delayed_node - PRIVATE graphene_app graphene_account_history graphene_market_history graphene_delayed_node graphene_chain graphene_egenesis_full fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_egenesis_full graphene_delayed_node ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS delayed_node diff --git a/programs/genesis_util/CMakeLists.txt b/programs/genesis_util/CMakeLists.txt index 9c3b278d..80a3c7b8 100644 --- a/programs/genesis_util/CMakeLists.txt +++ b/programs/genesis_util/CMakeLists.txt @@ -5,7 +5,7 @@ if( UNIX AND NOT APPLE ) endif() target_link_libraries( genesis_update - PRIVATE graphene_app graphene_chain graphene_egenesis_none fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_egenesis_none ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS genesis_update @@ -18,7 +18,7 @@ install( TARGETS add_executable( get_dev_key get_dev_key.cpp ) target_link_libraries( get_dev_key - PRIVATE graphene_app graphene_chain graphene_egenesis_none graphene_utilities fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS get_dev_key @@ -31,4 +31,4 @@ install( TARGETS add_executable( convert_address convert_address.cpp ) target_link_libraries( convert_address - PRIVATE graphene_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_chain ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/programs/js_operation_serializer/CMakeLists.txt b/programs/js_operation_serializer/CMakeLists.txt index dad8ded2..a49d164e 100644 --- a/programs/js_operation_serializer/CMakeLists.txt +++ b/programs/js_operation_serializer/CMakeLists.txt @@ -4,7 +4,7 @@ if( UNIX AND NOT APPLE ) endif() target_link_libraries( js_operation_serializer - PRIVATE graphene_app graphene_net graphene_chain graphene_egenesis_none graphene_utilities graphene_wallet fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS js_operation_serializer diff --git a/programs/size_checker/CMakeLists.txt b/programs/size_checker/CMakeLists.txt index 5e0a167c..a1a504a3 100644 --- a/programs/size_checker/CMakeLists.txt +++ b/programs/size_checker/CMakeLists.txt @@ -4,7 +4,7 @@ if( UNIX AND NOT APPLE ) endif() target_link_libraries( size_checker - PRIVATE graphene_chain graphene_egenesis_none fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_chain ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS size_checker diff --git a/programs/witness_node/CMakeLists.txt b/programs/witness_node/CMakeLists.txt index d5578379..806330d6 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_account_history graphene_affiliate_stats graphene_elasticsearch graphene_market_history graphene_witness graphene_chain graphene_debug_witness graphene_bookie graphene_egenesis_full graphene_snapshot graphene_es_objects fc peerplays_sidechain ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_egenesis_full graphene_snapshot graphene_witness peerplays_sidechain ${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/tests/CMakeLists.txt b/tests/CMakeLists.txt index 01474582..6ff915a9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,62 +1,65 @@ -file(GLOB COMMON_SOURCES "common/*.cpp") - find_package( Gperftools QUIET ) if( GPERFTOOLS_FOUND ) message( STATUS "Found gperftools; compiling tests with TCMalloc") list( APPEND PLATFORM_SPECIFIC_LIBS tcmalloc ) endif() +file(GLOB COMMON_SOURCES "common/*.cpp") +add_library(graphene_tests_common "${COMMON_SOURCES}" ) +target_link_libraries( graphene_tests_common + PUBLIC graphene_app graphene_egenesis_none ) + file(GLOB UNIT_TESTS "tests/*.cpp") -add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} ) -target_link_libraries( chain_test graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_bookie graphene_egenesis_none fc graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( chain_test ${UNIT_TESTS} ) +target_link_libraries( chain_test PRIVATE graphene_wallet graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( tests/serialization_tests.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) file(GLOB PERFORMANCE_TESTS "performance/*.cpp") -add_executable( performance_test ${PERFORMANCE_TESTS} ${COMMON_SOURCES} ) -target_link_libraries( performance_test graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_bookie graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( performance_test ${PERFORMANCE_TESTS} ) +target_link_libraries( performance_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB BENCH_MARKS "benchmarks/*.cpp") -add_executable( chain_bench ${BENCH_MARKS} ${COMMON_SOURCES} ) -target_link_libraries( chain_bench graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_bookie graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( chain_bench ${BENCH_MARKS} ) +target_link_libraries( chain_bench PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB APP_SOURCES "app/*.cpp") add_executable( app_test ${APP_SOURCES} ) -target_link_libraries( app_test graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_witness graphene_bookie graphene_net graphene_chain graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( app_test PRIVATE graphene_tests_common graphene_witness ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB INTENSE_SOURCES "intense/*.cpp") -add_executable( intense_test ${INTENSE_SOURCES} ${COMMON_SOURCES} ) -target_link_libraries( intense_test graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_bookie graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +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} ${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} ) +add_executable( betting_test ${BETTING_TESTS} ) +target_link_libraries( betting_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB PEERPLAYS_SIDECHAIN_TESTS "peerplays_sidechain/*.cpp") -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} ) +add_executable( peerplays_sidechain_test ${PEERPLAYS_SIDECHAIN_TESTS} ) +target_link_libraries( peerplays_sidechain_test PRIVATE graphene_tests_common peerplays_sidechain ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB TOURNAMENT_TESTS "tournament/*.cpp") -add_executable( tournament_test ${TOURNAMENT_TESTS} ${COMMON_SOURCES} ) -target_link_libraries( tournament_test graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( tournament_test ${TOURNAMENT_TESTS} ) +target_link_libraries( tournament_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB RANDOM_SOURCES "random/*.cpp") -add_executable( random_test ${RANDOM_SOURCES} ${COMMON_SOURCES} ) -target_link_libraries( random_test graphene_chain graphene_app graphene_elasticsearch graphene_es_objects graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( random_test ${RANDOM_SOURCES} ) +target_link_libraries( random_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB CLI_SOURCES "cli/*.cpp") add_executable( cli_test ${CLI_SOURCES} ) if(WIN32) list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32) endif() -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} ) +target_link_libraries( cli_test PRIVATE graphene_wallet graphene_tests_common graphene_witness ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( cli/main.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) file(GLOB ES_SOURCES "elasticsearch/*.cpp") -add_executable( es_test ${ES_SOURCES} ${COMMON_SOURCES} ) -target_link_libraries( es_test graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( es_test ${ES_SOURCES} ) +target_link_libraries( es_test PRIVATE graphene_tests_common ) add_subdirectory( generate_empty_blocks ) diff --git a/tests/betting/betting_tests.cpp b/tests/betting/betting_tests.cpp index cb6118a6..3898bb6c 100644 --- a/tests/betting/betting_tests.cpp +++ b/tests/betting/betting_tests.cpp @@ -132,114 +132,6 @@ using namespace graphene::chain::keywords; // 1.58 50:29 | 2.34 50:67 | 4.6 5:18 | 25 1:24 | 430 1:429 | // 1.59 100:59 | 2.36 25:34 | 4.7 10:37 -#define CREATE_ICE_HOCKEY_BETTING_MARKET(never_in_play, delay_before_settling) \ - create_sport({{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); \ - generate_blocks(1); \ - const sport_object& ice_hockey = *db.get_index_type().indices().get().rbegin(); \ - create_event_group({{"en", "NHL"}, {"zh_Hans", "國家冰球聯盟"}, {"ja", "ナショナルホッケーリーグ"}}, ice_hockey.id); \ - generate_blocks(1); \ - const event_group_object& nhl = *db.get_index_type().indices().get().rbegin(); \ - create_event({{"en", "Washington Capitals/Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑鷹"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホークス"}}, {{"en", "2016-17"}}, nhl.id); \ - generate_blocks(1); \ - const event_object& capitals_vs_blackhawks = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_rules({{"en", "NHL Rules v1.0"}}, {{"en", "The winner will be the team with the most points at the end of the game. The team with fewer points will not be the winner."}}); \ - generate_blocks(1); \ - const betting_market_rules_object& betting_market_rules = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), never_in_play, delay_before_settling); \ - generate_blocks(1); \ - const betting_market_group_object& moneyline_betting_markets = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_betting_markets.id, {{"en", "Washington Capitals win"}}); \ - generate_blocks(1); \ - const betting_market_object& capitals_win_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_betting_markets.id, {{"en", "Chicago Blackhawks win"}}); \ - generate_blocks(1); \ - const betting_market_object& blackhawks_win_market = *db.get_index_type().indices().get().rbegin(); \ - (void)capitals_win_market; (void)blackhawks_win_market; - -// create the basic betting market, plus groups for the first, second, and third period results -#define CREATE_EXTENDED_ICE_HOCKEY_BETTING_MARKET(never_in_play, delay_before_settling) \ - CREATE_ICE_HOCKEY_BETTING_MARKET(never_in_play, delay_before_settling) \ - create_betting_market_group({{"en", "First Period Result"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), never_in_play, delay_before_settling); \ - generate_blocks(1); \ - const betting_market_group_object& first_period_result_betting_markets = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(first_period_result_betting_markets.id, {{"en", "Washington Capitals win"}}); \ - generate_blocks(1); \ - const betting_market_object& first_period_capitals_win_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(first_period_result_betting_markets.id, {{"en", "Chicago Blackhawks win"}}); \ - generate_blocks(1); \ - const betting_market_object& first_period_blackhawks_win_market = *db.get_index_type().indices().get().rbegin(); \ - (void)first_period_capitals_win_market; (void)first_period_blackhawks_win_market; \ - \ - create_betting_market_group({{"en", "Second Period Result"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), never_in_play, delay_before_settling); \ - generate_blocks(1); \ - const betting_market_group_object& second_period_result_betting_markets = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(second_period_result_betting_markets.id, {{"en", "Washington Capitals win"}}); \ - generate_blocks(1); \ - const betting_market_object& second_period_capitals_win_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(second_period_result_betting_markets.id, {{"en", "Chicago Blackhawks win"}}); \ - generate_blocks(1); \ - const betting_market_object& second_period_blackhawks_win_market = *db.get_index_type().indices().get().rbegin(); \ - (void)second_period_capitals_win_market; (void)second_period_blackhawks_win_market; \ - \ - create_betting_market_group({{"en", "Third Period Result"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), never_in_play, delay_before_settling); \ - generate_blocks(1); \ - const betting_market_group_object& third_period_result_betting_markets = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(third_period_result_betting_markets.id, {{"en", "Washington Capitals win"}}); \ - generate_blocks(1); \ - const betting_market_object& third_period_capitals_win_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(third_period_result_betting_markets.id, {{"en", "Chicago Blackhawks win"}}); \ - generate_blocks(1); \ - const betting_market_object& third_period_blackhawks_win_market = *db.get_index_type().indices().get().rbegin(); \ - (void)third_period_capitals_win_market; (void)third_period_blackhawks_win_market; - -#define CREATE_TENNIS_BETTING_MARKET() \ - create_betting_market_rules({{"en", "Tennis Rules v1.0"}}, {{"en", "The winner is the player who wins the last ball in the match."}}); \ - generate_blocks(1); \ - const betting_market_rules_object& tennis_rules = *db.get_index_type().indices().get().rbegin(); \ - create_sport({{"en", "Tennis"}}); \ - generate_blocks(1); \ - const sport_object& tennis = *db.get_index_type().indices().get().rbegin(); \ - create_event_group({{"en", "Wimbledon"}}, tennis.id); \ - generate_blocks(1); \ - const event_group_object& wimbledon = *db.get_index_type().indices().get().rbegin(); \ - create_event({{"en", "R. Federer/T. Berdych"}}, {{"en", "2017"}}, wimbledon.id); \ - generate_blocks(1); \ - const event_object& berdych_vs_federer = *db.get_index_type().indices().get().rbegin(); \ - create_event({{"en", "M. Cilic/S. Querrye"}}, {{"en", "2017"}}, wimbledon.id); \ - generate_blocks(1); \ - const event_object& cilic_vs_querrey = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline 1st sf"}}, berdych_vs_federer.id, tennis_rules.id, asset_id_type(), false, 0); \ - generate_blocks(1); \ - const betting_market_group_object& moneyline_berdych_vs_federer = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline 2nd sf"}}, cilic_vs_querrey.id, tennis_rules.id, asset_id_type(), false, 0); \ - generate_blocks(1); \ - const betting_market_group_object& moneyline_cilic_vs_querrey = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_berdych_vs_federer.id, {{"en", "T. Berdych defeats R. Federer"}}); \ - generate_blocks(1); \ - const betting_market_object& berdych_wins_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_berdych_vs_federer.id, {{"en", "R. Federer defeats T. Berdych"}}); \ - generate_blocks(1); \ - const betting_market_object& federer_wins_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_cilic_vs_querrey.id, {{"en", "M. Cilic defeats S. Querrey"}}); \ - generate_blocks(1); \ - const betting_market_object& cilic_wins_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_cilic_vs_querrey.id, {{"en", "S. Querrey defeats M. Cilic"}});\ - generate_blocks(1); \ - const betting_market_object& querrey_wins_market = *db.get_index_type().indices().get().rbegin(); \ - create_event({{"en", "R. Federer/M. Cilic"}}, {{"en", "2017"}}, wimbledon.id); \ - generate_blocks(1); \ - const event_object& cilic_vs_federer = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline final"}}, cilic_vs_federer.id, tennis_rules.id, asset_id_type(), false, 0); \ - generate_blocks(1); \ - const betting_market_group_object& moneyline_cilic_vs_federer = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_cilic_vs_federer.id, {{"en", "R. Federer defeats M. Cilic"}}); \ - generate_blocks(1); \ - const betting_market_object& federer_wins_final_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_cilic_vs_federer.id, {{"en", "M. Cilic defeats R. Federer"}}); \ - generate_blocks(1); \ - const betting_market_object& cilic_wins_final_market = *db.get_index_type().indices().get().rbegin(); \ - (void)federer_wins_market;(void)cilic_wins_market;(void)federer_wins_final_market; (void)cilic_wins_final_market; (void)berdych_wins_market; (void)querrey_wins_market; - BOOST_FIXTURE_TEST_SUITE( betting_tests, database_fixture ) BOOST_AUTO_TEST_CASE(try_create_sport) @@ -309,12 +201,12 @@ BOOST_AUTO_TEST_CASE(simple_bet_win) transfer(account_id_type(), bob_id, asset(10000)); // place bets at 10:1 - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); // reverse positions at 1:1 - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(1100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(1100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(1100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(1100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); } FC_LOG_AND_RETHROW() } @@ -332,23 +224,23 @@ BOOST_AUTO_TEST_CASE(binned_order_books) transfer(account_id_type(), bob_id, asset(10000)); // place back bets at decimal odds of 1.55, 1.6, 1.65, 1.66, and 1.67 - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(100, asset_id_type()), 155 * GRAPHENE_BETTING_ODDS_PRECISION / 100); - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(100, asset_id_type()), 16 * GRAPHENE_BETTING_ODDS_PRECISION / 10); - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(100, asset_id_type()), 165 * GRAPHENE_BETTING_ODDS_PRECISION / 100); - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(100, asset_id_type()), 166 * GRAPHENE_BETTING_ODDS_PRECISION / 100); - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(100, asset_id_type()), 167 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(100, asset_id_type()), 155 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(100, asset_id_type()), 16 * GRAPHENE_BETTING_ODDS_PRECISION / 10); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(100, asset_id_type()), 165 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(100, asset_id_type()), 166 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(100, asset_id_type()), 167 * GRAPHENE_BETTING_ODDS_PRECISION / 100); const auto& bet_odds_idx = db.get_index_type().indices().get(); - auto bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); + auto bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); while (bet_iter != bet_odds_idx.end() && - bet_iter->betting_market_id == capitals_win_market.id) + bet_iter->betting_market_id == capitals_win_market_id) { idump((*bet_iter)); ++bet_iter; } - graphene::bookie::binned_order_book binned_orders_point_one = bookie_api.get_binned_order_book(capitals_win_market.id, 1); + graphene::bookie::binned_order_book binned_orders_point_one = bookie_api.get_binned_order_book(capitals_win_market_id, 1); idump((binned_orders_point_one)); // the binned orders returned should be chosen so that we if we assume those orders are real and we place @@ -362,28 +254,28 @@ BOOST_AUTO_TEST_CASE(binned_order_books) // compute the matching lay order share_type lay_amount = bet_object::get_approximate_matching_amount(binned_order.amount_to_bet, binned_order.backer_multiplier, bet_type::back, true /* round up */); ilog("Alice is laying with ${lay_amount} at odds ${odds} to match the binned back amount ${back_amount}", ("lay_amount", lay_amount)("odds", binned_order.backer_multiplier)("back_amount", binned_order.amount_to_bet)); - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(lay_amount, asset_id_type()), binned_order.backer_multiplier); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(lay_amount, asset_id_type()), binned_order.backer_multiplier); } - bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); + bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); while (bet_iter != bet_odds_idx.end() && - bet_iter->betting_market_id == capitals_win_market.id) + bet_iter->betting_market_id == capitals_win_market_id) { idump((*bet_iter)); ++bet_iter; } - BOOST_CHECK(bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)) == bet_odds_idx.end()); + BOOST_CHECK(bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)) == bet_odds_idx.end()); // place lay bets at decimal odds of 1.55, 1.6, 1.65, 1.66, and 1.67 // these bets will get rounded down, actual amounts are 99, 99, 91, 99, and 67 -// place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 155 * GRAPHENE_BETTING_ODDS_PRECISION / 100); -// place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 155 * GRAPHENE_BETTING_ODDS_PRECISION / 100); -// place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 165 * GRAPHENE_BETTING_ODDS_PRECISION / 100); -// place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 165 * GRAPHENE_BETTING_ODDS_PRECISION / 100); -// place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 165 * GRAPHENE_BETTING_ODDS_PRECISION / 100); +// place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 155 * GRAPHENE_BETTING_ODDS_PRECISION / 100); +// place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 155 * GRAPHENE_BETTING_ODDS_PRECISION / 100); +// place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 165 * GRAPHENE_BETTING_ODDS_PRECISION / 100); +// place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 165 * GRAPHENE_BETTING_ODDS_PRECISION / 100); +// place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 165 * GRAPHENE_BETTING_ODDS_PRECISION / 100); // -// binned_orders_point_one = bookie_api.get_binned_order_book(capitals_win_market.id, 1); +// binned_orders_point_one = bookie_api.get_binned_order_book(capitals_win_market_id, 1); // idump((binned_orders_point_one)); // // // the binned orders returned should be chosen so that we if we assume those orders are real and we place @@ -397,20 +289,20 @@ BOOST_AUTO_TEST_CASE(binned_order_books) // // compute the matching lay order // share_type back_amount = bet_object::get_approximate_matching_amount(binned_order.amount_to_bet, binned_order.backer_multiplier, bet_type::lay, true /* round up */); // ilog("Alice is backing with ${back_amount} at odds ${odds} to match the binned lay amount ${lay_amount}", ("back_amount", back_amount)("odds", binned_order.backer_multiplier)("lay_amount", binned_order.amount_to_bet)); -// place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(back_amount, asset_id_type()), binned_order.backer_multiplier); +// place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(back_amount, asset_id_type()), binned_order.backer_multiplier); // // } // // -// bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); +// bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); // while (bet_iter != bet_odds_idx.end() && -// bet_iter->betting_market_id == capitals_win_market.id) +// bet_iter->betting_market_id == capitals_win_market_id) // { // idump((*bet_iter)); // ++bet_iter; // } // -// BOOST_CHECK(bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)) == bet_odds_idx.end()); +// BOOST_CHECK(bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)) == bet_odds_idx.end()); // } FC_LOG_AND_RETHROW() } @@ -427,19 +319,19 @@ BOOST_AUTO_TEST_CASE( peerplays_sport_create_test ) transfer(account_id_type(), bob_id, asset(10000000)); // have bob lay a bet for 1M (+20k fees) at 1:1 odds - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // have alice back a matching bet at 1:1 odds (also costing 1.02M) - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); // caps win - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); @@ -464,18 +356,18 @@ BOOST_AUTO_TEST_CASE( cancel_unmatched_in_betting_group_test ) transfer(account_id_type(), bob_id, asset(10000000)); // have bob lay a bet for 1M (+20k fees) at 1:1 odds - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // have alice back a matching bet at 1:1 odds (also costing 1.02M) - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // place unmatched - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(bob_id, blackhawks_win_market.id, bet_type::lay, asset(600, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, blackhawks_win_market_id, bet_type::lay, asset(600, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000 - 500); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000 - 600); // cancel unmatched - cancel_unmatched_bets(moneyline_betting_markets.id); + cancel_unmatched_bets(moneyline_betting_markets_id); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000); @@ -498,19 +390,19 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts) // lay 46 at 1.94 odds (50:47) -- this is too small to be placed on the books and there's // nothing for it to match, so it should be canceled BOOST_TEST_MESSAGE("lay 46 at 1.94 odds (50:47) -- this is too small to be placed on the books and there's nothing for it to match, so it should be canceled"); - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(46, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(46, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); BOOST_TEST_MESSAGE("alice's balance should be " << alice_expected_balance.value); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); ilog("message"); // lay 47 at 1.94 odds (50:47) -- this is an exact amount, nothing surprising should happen here BOOST_TEST_MESSAGE("alice lays 470 at 1.94 odds (50:47) -- this is an exact amount, nothing surprising should happen here"); - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(47, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(47, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 47; BOOST_TEST_MESSAGE("alice's balance should be " << alice_expected_balance.value); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // lay 100 at 1.91 odds (100:91) -- this is an inexact match, we should get refunded 9 and leave a bet for 91 on the books - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 191 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 191 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 91; BOOST_TEST_MESSAGE("alice's balance should be " << alice_expected_balance.value); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); @@ -528,7 +420,7 @@ ilog("message"); // bob's balance goes down by 300 (150 is matched, 150 is still on the books) // leaves a back bet of 150 @ 1.5 on the books BOOST_TEST_MESSAGE("now have bob match it with a back of 300 at 1.5"); - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(300, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(300, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); bob_expected_balance -= 300; BOOST_TEST_MESSAGE("bob's balance should be " << bob_expected_balance.value); BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); @@ -550,7 +442,7 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts2) // lay 470 at 1.94 odds (50:47) -- this is an exact amount, nothing surprising should happen here BOOST_TEST_MESSAGE("alice lays 470 at 1.94 odds (50:47) -- this is an exact amount, nothing surprising should happen here"); - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(470, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(470, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 470; BOOST_TEST_MESSAGE("alice's balance should be " << alice_expected_balance.value); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); @@ -565,7 +457,7 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts2) // bob's balance goes down by the 900 he paid (500 matched, 400 unmatched) // alice's bet is completely removed from the books. BOOST_TEST_MESSAGE("now have bob match it with a back of 900 at 1.5"); - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(900, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(900, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); bob_expected_balance -= 900; BOOST_TEST_MESSAGE("bob's balance should be " << bob_expected_balance.value); @@ -587,7 +479,7 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts3) BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // lay 470 at 1.94 odds (50:47) -- this is an exact amount, nothing surprising should happen here - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(470, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(470, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 470; BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); @@ -600,7 +492,7 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts3) // match all of the 470 @ 1.94 with 500, and leave 500 left on the books // bob's balance goes down by the 1000 he paid, 500 matching, 500 unmatching // alice's bet is removed from the books - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(1000, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(1000, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); bob_expected_balance -= 1000; BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); } @@ -620,12 +512,12 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts4) BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // back 1000 at 1.89 odds (100:89) -- this is an exact amount, nothing surprising should happen here - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000, asset_id_type()), 189 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000, asset_id_type()), 189 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 1000; BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // back 1000 at 1.97 odds (100:97) -- again, this is an exact amount, nothing surprising should happen here - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000, asset_id_type()), 197 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000, asset_id_type()), 197 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 1000; BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); @@ -655,7 +547,7 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts4) // * alice's top bet on the books is reduced 200 @ 1.97 // * Bob now has as much of a position as he was willing to buy. We refund // the remainder of his bet, which is 552 - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(3000, asset_id_type()), 266 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(3000, asset_id_type()), 266 * GRAPHENE_BETTING_ODDS_PRECISION / 100); bob_expected_balance -= 3000 - 12 - 770 - 552; BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); } @@ -675,7 +567,7 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts5) BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // back 1100 at 1.86 odds (50:43) -- this is an exact amount, nothing surprising should happen here - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1100, asset_id_type()), 186 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1100, asset_id_type()), 186 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 1100; BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); @@ -699,7 +591,7 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts5) // * bob's bet is fully matched, he is refunded the remaining 132 and his // bet is complete // * bob's balance is reduced by the 946 he paid - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1100, asset_id_type()), 198 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1100, asset_id_type()), 198 * GRAPHENE_BETTING_ODDS_PRECISION / 100); bob_expected_balance -= 1100 - 22 - 132; BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); } @@ -720,40 +612,40 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts6) share_type alice_expected_balance = 1000000000; BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(10000000, asset_id_type()), 13 * GRAPHENE_BETTING_ODDS_PRECISION / 10); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(10000000, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(10000000, asset_id_type()), 16 * GRAPHENE_BETTING_ODDS_PRECISION / 10); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(10000000, asset_id_type()), 13 * GRAPHENE_BETTING_ODDS_PRECISION / 10); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(10000000, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(10000000, asset_id_type()), 16 * GRAPHENE_BETTING_ODDS_PRECISION / 10); alice_expected_balance -= 30000000; BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // check order books to see they match the bets we placed const auto& bet_odds_idx = db.get_index_type().indices().get(); - auto bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); + auto bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); BOOST_REQUIRE(bet_iter != bet_odds_idx.end()); - BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market.id); + BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market_id); BOOST_REQUIRE(bet_iter->bettor_id == alice_id); BOOST_REQUIRE(bet_iter->amount_to_bet == asset(10000000, asset_id_type())); BOOST_REQUIRE(bet_iter->backer_multiplier == 13 * GRAPHENE_BETTING_ODDS_PRECISION / 10); BOOST_REQUIRE(bet_iter->back_or_lay == bet_type::back); ++bet_iter; BOOST_REQUIRE(bet_iter != bet_odds_idx.end()); - BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market.id); + BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market_id); BOOST_REQUIRE(bet_iter->bettor_id == alice_id); BOOST_REQUIRE(bet_iter->amount_to_bet == asset(10000000, asset_id_type())); BOOST_REQUIRE(bet_iter->backer_multiplier == 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); BOOST_REQUIRE(bet_iter->back_or_lay == bet_type::back); ++bet_iter; BOOST_REQUIRE(bet_iter != bet_odds_idx.end()); - BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market.id); + BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market_id); BOOST_REQUIRE(bet_iter->bettor_id == alice_id); BOOST_REQUIRE(bet_iter->amount_to_bet == asset(10000000, asset_id_type())); BOOST_REQUIRE(bet_iter->backer_multiplier == 16 * GRAPHENE_BETTING_ODDS_PRECISION / 10); BOOST_REQUIRE(bet_iter->back_or_lay == bet_type::back); ++bet_iter; - BOOST_REQUIRE(bet_iter == bet_odds_idx.end() || bet_iter->betting_market_id != capitals_win_market.id); + BOOST_REQUIRE(bet_iter == bet_odds_idx.end() || bet_iter->betting_market_id != capitals_win_market_id); // check the binned order books from the bookie plugin to make sure they match - graphene::bookie::binned_order_book binned_orders_point_one = bookie_api.get_binned_order_book(capitals_win_market.id, 1); + graphene::bookie::binned_order_book binned_orders_point_one = bookie_api.get_binned_order_book(capitals_win_market_id, 1); auto aggregated_back_bets_iter = binned_orders_point_one.aggregated_back_bets.begin(); BOOST_REQUIRE(aggregated_back_bets_iter != binned_orders_point_one.aggregated_back_bets.end()); BOOST_REQUIRE(aggregated_back_bets_iter->amount_to_bet.value == 10000000); @@ -774,11 +666,11 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts6) share_type bob_expected_balance = 1000000000; BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(5000000, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(5000000, asset_id_type()), 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); ilog("Order books after bob's matching lay bet:"); - bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); + bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); while (bet_iter != bet_odds_idx.end() && - bet_iter->betting_market_id == capitals_win_market.id) + bet_iter->betting_market_id == capitals_win_market_id) { idump((*bet_iter)); ++bet_iter; @@ -788,25 +680,25 @@ BOOST_AUTO_TEST_CASE(match_using_takers_expected_amounts6) BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); // check order books to see they match after bob's bet matched - bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); + bet_iter = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); BOOST_REQUIRE(bet_iter != bet_odds_idx.end()); - BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market.id); + BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market_id); BOOST_REQUIRE(bet_iter->bettor_id == alice_id); BOOST_REQUIRE(bet_iter->amount_to_bet == asset(10000000, asset_id_type())); BOOST_REQUIRE(bet_iter->backer_multiplier == 15 * GRAPHENE_BETTING_ODDS_PRECISION / 10); BOOST_REQUIRE(bet_iter->back_or_lay == bet_type::back); ++bet_iter; BOOST_REQUIRE(bet_iter != bet_odds_idx.end()); - BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market.id); + BOOST_REQUIRE(bet_iter->betting_market_id == capitals_win_market_id); BOOST_REQUIRE(bet_iter->bettor_id == alice_id); BOOST_REQUIRE(bet_iter->amount_to_bet == asset(10000000, asset_id_type())); BOOST_REQUIRE(bet_iter->backer_multiplier == 16 * GRAPHENE_BETTING_ODDS_PRECISION / 10); BOOST_REQUIRE(bet_iter->back_or_lay == bet_type::back); ++bet_iter; - BOOST_REQUIRE(bet_iter == bet_odds_idx.end() || bet_iter->betting_market_id != capitals_win_market.id); + BOOST_REQUIRE(bet_iter == bet_odds_idx.end() || bet_iter->betting_market_id != capitals_win_market_id); // check the binned order books from the bookie plugin to make sure they match - binned_orders_point_one = bookie_api.get_binned_order_book(capitals_win_market.id, 1); + binned_orders_point_one = bookie_api.get_binned_order_book(capitals_win_market_id, 1); aggregated_back_bets_iter = binned_orders_point_one.aggregated_back_bets.begin(); BOOST_REQUIRE(aggregated_back_bets_iter != binned_orders_point_one.aggregated_back_bets.end()); BOOST_REQUIRE(aggregated_back_bets_iter->amount_to_bet.value == 10000000); @@ -838,16 +730,16 @@ BOOST_AUTO_TEST_CASE(inexact_odds) // lay 46 at 1.94 odds (50:47) -- this is too small to be placed on the books and there's // nothing for it to match, so it should be canceled - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(46, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(46, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // lay 47 at 1.94 odds (50:47) -- this is an exact amount, nothing surprising should happen here - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(47, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(47, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 47; BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // lay 100 at 1.91 odds (100:91) -- this is an inexact match, we should get refunded 9 and leave a bet for 91 on the books - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 191 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 191 * GRAPHENE_BETTING_ODDS_PRECISION / 100); alice_expected_balance -= 91; BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); @@ -863,7 +755,7 @@ BOOST_AUTO_TEST_CASE(inexact_odds) // leaving 150 // back bets at 100:91 must be a multiple of 100, so refund 50 // leaves a back bet of 100 @ 1.91 on the books - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(300, asset_id_type()), 191 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(300, asset_id_type()), 191 * GRAPHENE_BETTING_ODDS_PRECISION / 100); bob_expected_balance -= 250; BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); } @@ -884,15 +776,15 @@ BOOST_AUTO_TEST_CASE(bet_reversal_test) BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); // back with our entire balance - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(10000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(10000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), 0); // reverse the bet - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(20000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(20000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), 0); // try to re-reverse it, but go too far - BOOST_CHECK_THROW( place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(30000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION), fc::exception); + BOOST_CHECK_THROW( place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(30000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION), fc::exception); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), 0); } FC_LOG_AND_RETHROW() @@ -916,21 +808,21 @@ BOOST_AUTO_TEST_CASE(bet_reversal_test) // BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance); // // // back with alice's entire balance -// place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(10000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); +// place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(10000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // alice_expected_balance -= 10000000; // BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance); // // // lay with bob's entire balance, which fully matches bob's bet -// place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(10000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); +// place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(10000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // bob_expected_balance -= 10000000; // BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance); // // // reverse the bet -// place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(20000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); +// place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(20000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance); // // // try to re-reverse it, but go too far -// BOOST_CHECK_THROW( place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(30000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION), fc::exception); +// BOOST_CHECK_THROW( place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(30000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION), fc::exception); // BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance); // } // FC_LOG_AND_RETHROW() @@ -952,11 +844,11 @@ BOOST_AUTO_TEST_CASE(persistent_objects_test) BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); - idump((capitals_win_market.get_status())); + idump((capitals_win_market_id(db).get_status())); // lay 46 at 1.94 odds (50:47) -- this is too small to be placed on the books and there's // nothing for it to match, so it should be canceled - bet_id_type automatically_canceled_bet_id = place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(46, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + bet_id_type automatically_canceled_bet_id = place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(46, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); generate_blocks(1); BOOST_CHECK_MESSAGE(!db.find(automatically_canceled_bet_id), "Bet should have been canceled, but the blockchain still knows about it"); fc::variants objects_from_bookie = bookie_api.get_objects({automatically_canceled_bet_id}); @@ -965,7 +857,7 @@ BOOST_AUTO_TEST_CASE(persistent_objects_test) BOOST_CHECK_MESSAGE(objects_from_bookie[0]["id"].as(1) == automatically_canceled_bet_id, "Bookie Plugin didn't return a deleted bet it"); // lay 47 at 1.94 odds (50:47) -- this bet should go on the order books normally - bet_id_type first_bet_on_books = place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(47, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + bet_id_type first_bet_on_books = place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(47, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); generate_blocks(1); BOOST_CHECK_MESSAGE(db.find(first_bet_on_books), "Bet should exist on the blockchain"); objects_from_bookie = bookie_api.get_objects({first_bet_on_books}); @@ -974,7 +866,7 @@ BOOST_AUTO_TEST_CASE(persistent_objects_test) BOOST_CHECK_MESSAGE(objects_from_bookie[0]["id"].as(1) == first_bet_on_books, "Bookie Plugin didn't return a bet that is currently on the books"); // place a bet that exactly matches 'first_bet_on_books', should result in empty books (thus, no bet_objects from the blockchain) - bet_id_type matching_bet = place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(50, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); + bet_id_type matching_bet = place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(50, asset_id_type()), 194 * GRAPHENE_BETTING_ODDS_PRECISION / 100); BOOST_CHECK_MESSAGE(!db.find(first_bet_on_books), "Bet should have been filled, but the blockchain still knows about it"); BOOST_CHECK_MESSAGE(!db.find(matching_bet), "Bet should have been filled, but the blockchain still knows about it"); generate_blocks(1); // the bookie plugin doesn't detect matches until a block is generated @@ -985,17 +877,11 @@ BOOST_AUTO_TEST_CASE(persistent_objects_test) BOOST_CHECK_MESSAGE(objects_from_bookie[0]["id"].as(1) == first_bet_on_books, "Bookie Plugin didn't return a bet that has been filled"); BOOST_CHECK_MESSAGE(objects_from_bookie[1]["id"].as(1) == matching_bet, "Bookie Plugin didn't return a bet that has been filled"); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::cancel}, - {blackhawks_win_market.id, betting_market_resolution_type::cancel}}); - - // as soon as the market is resolved during the generate_block(), these markets - // should be deleted and our references will go out of scope. Save the - // market ids here so we can verify that they were really deleted - betting_market_id_type capitals_win_market_id = capitals_win_market.id; - betting_market_id_type blackhawks_win_market_id = blackhawks_win_market.id; + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::cancel}, + {blackhawks_win_market_id, betting_market_resolution_type::cancel}}); generate_blocks(1); @@ -1049,25 +935,19 @@ BOOST_AUTO_TEST_CASE(test_settled_market_states) BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance.value); BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance.value); - idump((capitals_win_market.get_status())); + idump((capitals_win_market_id(db).get_status())); BOOST_TEST_MESSAGE("setting the event to in_progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); - - // as soon as the market is resolved during the generate_block(), these markets - // should be deleted and our references will go out of scope. Save the - // market ids here so we can verify that they were really deleted - betting_market_id_type capitals_win_market_id = capitals_win_market.id; - betting_market_id_type blackhawks_win_market_id = blackhawks_win_market.id; + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); @@ -1098,7 +978,7 @@ BOOST_AUTO_TEST_CASE(delayed_bets_test) // test live betting generate_blocks(1); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::in_play); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::in_play); generate_blocks(1); transfer(account_id_type(), alice_id, asset(10000000)); @@ -1113,17 +993,17 @@ BOOST_AUTO_TEST_CASE(delayed_bets_test) // test live betting BOOST_TEST_MESSAGE("Testing basic delayed bet mechanics"); // alice backs 100 at odds 2 BOOST_TEST_MESSAGE("Alice places a back bet of 100 at odds 2.0"); - bet_id_type delayed_back_bet = place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + bet_id_type delayed_back_bet = place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); generate_blocks(1); // verify the bet hasn't been placed in the active book - auto first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); + auto first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); BOOST_CHECK(first_bet_in_market == bet_odds_idx.end()); // after 3 blocks, the delay should have expired and it will be promoted to the active book generate_blocks(2); - first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); - auto last_bet_in_market = bet_odds_idx.upper_bound(std::make_tuple(capitals_win_market.id)); + first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); + auto last_bet_in_market = bet_odds_idx.upper_bound(std::make_tuple(capitals_win_market_id)); BOOST_CHECK(first_bet_in_market != bet_odds_idx.end()); BOOST_CHECK(std::distance(first_bet_in_market, last_bet_in_market) == 1); @@ -1131,19 +1011,19 @@ BOOST_AUTO_TEST_CASE(delayed_bets_test) // test live betting edump((bet)); // bob lays 100 at odds 2 to match alice's bet currently on the books BOOST_TEST_MESSAGE("Bob places a lay bet of 100 at odds 2.0"); - /* bet_id_type delayed_lay_bet = */ place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + /* bet_id_type delayed_lay_bet = */ place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); edump((db.get_global_properties().parameters.block_interval)(db.head_block_time())); // the bet should not enter the order books before a block has been generated - first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); - last_bet_in_market = bet_odds_idx.upper_bound(std::make_tuple(capitals_win_market.id)); + first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); + last_bet_in_market = bet_odds_idx.upper_bound(std::make_tuple(capitals_win_market_id)); for (const auto& bet : bet_odds_idx) edump((bet)); generate_blocks(1); // bob's bet will still be delayed, so the active order book will only contain alice's bet - first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); - last_bet_in_market = bet_odds_idx.upper_bound(std::make_tuple(capitals_win_market.id)); + first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); + last_bet_in_market = bet_odds_idx.upper_bound(std::make_tuple(capitals_win_market_id)); // edump((std::distance(first_bet_in_market, last_bet_in_market))); BOOST_CHECK(std::distance(first_bet_in_market, last_bet_in_market) == 1); for (const auto& bet : boost::make_iterator_range(first_bet_in_market, last_bet_in_market)) @@ -1156,13 +1036,13 @@ BOOST_AUTO_TEST_CASE(delayed_bets_test) // test live betting // now test that when we cancel all bets on a market, delayed bets get canceled too BOOST_TEST_MESSAGE("Alice places a back bet of 100 at odds 2.0"); - delayed_back_bet = place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + delayed_back_bet = place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); generate_blocks(1); - first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market.id)); + first_bet_in_market = bet_odds_idx.lower_bound(std::make_tuple(capitals_win_market_id)); BOOST_CHECK(!bet_odds_idx.empty()); BOOST_CHECK(first_bet_in_market == bet_odds_idx.end()); BOOST_TEST_MESSAGE("Cancel all bets"); - cancel_unmatched_bets(moneyline_betting_markets.id); + cancel_unmatched_bets(moneyline_betting_markets_id); BOOST_CHECK(bet_odds_idx.empty()); } FC_LOG_AND_RETHROW() @@ -1283,28 +1163,28 @@ BOOST_AUTO_TEST_CASE( testnet_witness_block_production_error ) try { CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); - create_betting_market_group({{"en", "Unused"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), false, 0); + create_betting_market_group({{"en", "Unused"}}, capitals_vs_blackhawks_id, betting_market_rules_id, asset_id_type(), false, 0); generate_blocks(1); const betting_market_group_object& unused_betting_markets = *db.get_index_type().indices().get().rbegin(); BOOST_TEST_MESSAGE("setting the event in progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); BOOST_CHECK(unused_betting_markets.get_status() == betting_market_group_status::in_play); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_CHECK(unused_betting_markets.get_status() == betting_market_group_status::closed); BOOST_TEST_MESSAGE("setting the event to canceled"); - update_event(capitals_vs_blackhawks.id, _status = event_status::canceled); + update_event(capitals_vs_blackhawks_id, _status = event_status::canceled); generate_blocks(1); } FC_LOG_AND_RETHROW() } @@ -1318,10 +1198,10 @@ BOOST_AUTO_TEST_CASE( cancel_one_event_in_group ) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); // create a second event in the same betting market group - create_event({{"en", "Boston Bruins/Pittsburgh Penguins"}}, {{"en", "2016-17"}}, nhl.id); + create_event({{"en", "Boston Bruins/Pittsburgh Penguins"}}, {{"en", "2016-17"}}, nhl_id); generate_blocks(1); const event_object& bruins_vs_penguins = *db.get_index_type().indices().get().rbegin(); - create_betting_market_group({{"en", "Moneyline"}}, bruins_vs_penguins.id, betting_market_rules.id, asset_id_type(), false, 0); + create_betting_market_group({{"en", "Moneyline"}}, bruins_vs_penguins.id, betting_market_rules_id, asset_id_type(), false, 0); generate_blocks(1); const betting_market_group_object& bruins_penguins_moneyline_betting_markets = *db.get_index_type().indices().get().rbegin(); create_betting_market(bruins_penguins_moneyline_betting_markets.id, {{"en", "Boston Bruins win"}}); @@ -1333,14 +1213,14 @@ BOOST_AUTO_TEST_CASE( cancel_one_event_in_group ) (void)bruins_win_market; (void)penguins_win_market; // check the initial state - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); BOOST_CHECK(bruins_vs_penguins.get_status() == event_status::upcoming); BOOST_TEST_MESSAGE("setting the capitals_vs_blackhawks event to in-progress, leaving bruins_vs_penguins in upcoming"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); BOOST_CHECK(bruins_vs_penguins.get_status() == event_status::upcoming); BOOST_CHECK(bruins_penguins_moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); @@ -1348,19 +1228,19 @@ BOOST_AUTO_TEST_CASE( cancel_one_event_in_group ) BOOST_CHECK(penguins_win_market.get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the capitals_vs_blackhawks event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_CHECK(bruins_vs_penguins.get_status() == event_status::upcoming); BOOST_CHECK(bruins_penguins_moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); BOOST_CHECK(bruins_win_market.get_status() == betting_market_status::unresolved); BOOST_CHECK(penguins_win_market.get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the capitals_vs_blackhawks event to canceled"); - update_event(capitals_vs_blackhawks.id, _status = event_status::canceled); + update_event(capitals_vs_blackhawks_id, _status = event_status::canceled); generate_blocks(1); BOOST_CHECK(bruins_vs_penguins.get_status() == event_status::upcoming); BOOST_CHECK(bruins_penguins_moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); @@ -1456,23 +1336,23 @@ struct simple_bet_test_fixture_2 : database_fixture { transfer(account_id_type(), bob_id, asset(10000)); // alice backs 1000 at 1:1, matches - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // now alice lays at 2500 at 1:1. This should require a deposit of 500, with the remaining 200 being funded from exposure - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(2500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(2500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // match the bet bit by bit. bob matches 500 of alice's 2500 bet. This effectively cancels half of bob's lay position // so he immediately gets 500 back. It reduces alice's back position, but doesn't return any money to her (all 2000 of her exposure // was already "promised" to her lay bet, so the 500 she would have received is placed in her refundable_unmatched_bets) - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); // match another 500, which will fully cancel bob's lay position and return the other 500 he had locked up in his position. // alice's back position is now canceled, 1500 remains of her unmatched lay bet, and the 500 from canceling her position has // been moved to her refundable_unmatched_bets - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - capitals_win_betting_market_id = capitals_win_market.id; + capitals_win_betting_market_id = capitals_win_market_id; } }; @@ -1484,10 +1364,10 @@ BOOST_AUTO_TEST_CASE(sport_update_test) { ACTORS( (alice) ); CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); - update_sport(ice_hockey.id, {{"en", "Hockey on Ice"}, {"zh_Hans", "冰"}, {"ja", "アイスホッケ"}}); + update_sport(ice_hockey_id, {{"en", "Hockey on Ice"}, {"zh_Hans", "冰"}, {"ja", "アイスホッケ"}}); transfer(account_id_type(), alice_id, asset(10000000)); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); @@ -1500,13 +1380,13 @@ BOOST_AUTO_TEST_CASE(sport_delete_test) { CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); - const auto& event_group_1 = create_event_group({{"en", "group1"}}, ice_hockey.id); - const auto& event_group_2 = create_event_group({{"en", "group2"}}, ice_hockey.id); + const auto& event_group_1 = create_event_group({{"en", "group1"}}, ice_hockey_id); + const auto& event_group_2 = create_event_group({{"en", "group2"}}, ice_hockey_id); - delete_sport(ice_hockey.id); + delete_sport(ice_hockey_id); const auto& sport_by_id = db.get_index_type().indices().get(); - BOOST_CHECK(sport_by_id.end() == sport_by_id.find(ice_hockey.id)); + BOOST_CHECK(sport_by_id.end() == sport_by_id.find(ice_hockey_id)); const auto& event_group_by_id = db.get_index_type().indices().get(); BOOST_CHECK(event_group_by_id.end() == event_group_by_id.find(event_group_1.id)); @@ -1521,7 +1401,7 @@ BOOST_AUTO_TEST_CASE(sport_delete_test_not_proposal) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); sport_delete_operation sport_delete_op; - sport_delete_op.sport_id = ice_hockey.id; + sport_delete_op.sport_id = ice_hockey_id; BOOST_CHECK_THROW(force_operation_by_witnesses(sport_delete_op), fc::exception); } FC_LOG_AND_RETHROW() @@ -1534,9 +1414,9 @@ BOOST_AUTO_TEST_CASE(sport_delete_test_not_proposal) // { // CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); // -// delete_sport(ice_hockey.id); +// delete_sport(ice_hockey_id); // -// BOOST_CHECK_THROW(delete_sport(ice_hockey.id), fc::exception); +// BOOST_CHECK_THROW(delete_sport(ice_hockey_id), fc::exception); // } FC_LOG_AND_RETHROW() // } @@ -1550,28 +1430,28 @@ BOOST_AUTO_TEST_CASE(event_group_update_test) transfer(account_id_type(), alice_id, asset(10000000)); transfer(account_id_type(), bob_id, asset(10000000)); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); const sport_object& ice_on_hockey = create_sport({{"en", "Hockey on Ice"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); \ fc::optional sport_id = ice_on_hockey.id; fc::optional name = internationalized_string_type({{"en", "IBM"}, {"zh_Hans", "國家冰球聯"}, {"ja", "ナショナルホッケーリー"}}); - update_event_group(nhl.id, fc::optional(), name); - update_event_group(nhl.id, sport_id, fc::optional()); - update_event_group(nhl.id, sport_id, name); + update_event_group(nhl_id, fc::optional(), name); + update_event_group(nhl_id, sport_id, fc::optional()); + update_event_group(nhl_id, sport_id, name); - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); // caps win - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); @@ -1760,9 +1640,9 @@ BOOST_AUTO_TEST_CASE(event_group_delete_test) transfer(account_id_type(), alice_id, asset(initialAccountAsset)); transfer(account_id_type(), bob_id, asset(initialAccountAsset)); - const auto& event = create_event({{"en", "event"}}, {{"en", "2016-17"}}, nhl.id); + const auto& event = create_event({{"en", "event"}}, {{"en", "2016-17"}}, nhl_id); - const auto& market_group = create_betting_market_group({{"en", "market group"}}, event.id, betting_market_rules.id, asset_id_type(), false, 0); + const auto& market_group = create_betting_market_group({{"en", "market group"}}, event.id, betting_market_rules_id, asset_id_type(), false, 0); //to make bets be not removed immediately update_betting_market_group_impl(market_group.id, fc::optional(), @@ -1772,17 +1652,17 @@ BOOST_AUTO_TEST_CASE(event_group_delete_test) const auto& market = create_betting_market(market_group.id, {{"en", "market"}}); - test_events events(*this, nhl.id); - test_markets_groups markets_groups(*this, event.id, betting_market_rules.id); + test_events events(*this, nhl_id); + test_markets_groups markets_groups(*this, event.id, betting_market_rules_id); test_markets markets(*this, market_group.id); const auto& bet_1_id = place_bet(alice_id, market.id, bet_type::back, asset(betAsset, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); const auto& bet_2_id = place_bet(bob_id, market.id, bet_type::lay, asset(betAsset, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - delete_event_group(nhl.id); + delete_event_group(nhl_id); const auto& event_group_by_id = db.get_index_type().indices().get(); - BOOST_CHECK(event_group_by_id.end() == event_group_by_id.find(nhl.id)); + BOOST_CHECK(event_group_by_id.end() == event_group_by_id.find(nhl_id)); BOOST_CHECK(event_status::canceled == event.get_status()); @@ -1838,11 +1718,11 @@ BOOST_AUTO_TEST_CASE(event_group_delete_test_with_matched_bets) transfer(account_id_type(), bob_id, asset(initialAccountAsset)); generate_blocks(1); - create_event({{"en", "event"}}, {{"en", "2016-17"}}, nhl.id); + create_event({{"en", "event"}}, {{"en", "2016-17"}}, nhl_id); generate_blocks(1); const event_object& event = *db.get_index_type().indices().get().rbegin(); - create_betting_market_group({{"en", "market group"}}, event.id, betting_market_rules.id, asset_id_type(), false, 0); + create_betting_market_group({{"en", "market group"}}, event.id, betting_market_rules_id, asset_id_type(), false, 0); generate_blocks(1); const betting_market_group_object& market_group = *db.get_index_type().indices().get().rbegin(); @@ -1854,7 +1734,7 @@ BOOST_AUTO_TEST_CASE(event_group_delete_test_with_matched_bets) place_bet(bob_id, market.id, bet_type::lay, asset(betAsset, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); generate_blocks(1); - delete_event_group(nhl.id); + delete_event_group(nhl_id); generate_blocks(1); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), initialAccountAsset); @@ -1869,7 +1749,7 @@ BOOST_AUTO_TEST_CASE(event_group_delete_test_not_proposal) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); event_group_delete_operation event_group_delete_op; - event_group_delete_op.event_group_id = nhl.id; + event_group_delete_op.event_group_id = nhl_id; BOOST_CHECK_THROW(force_operation_by_witnesses(event_group_delete_op), fc::exception); } FC_LOG_AND_RETHROW() @@ -1880,7 +1760,6 @@ BOOST_AUTO_TEST_CASE(event_group_delete_test_not_existed_event_group) try { CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); - event_group_id_type nhl_id = nhl.id; delete_event_group(nhl_id); BOOST_CHECK_THROW(delete_event_group(nhl_id), fc::exception); @@ -1897,31 +1776,31 @@ BOOST_AUTO_TEST_CASE(event_update_test) transfer(account_id_type(), alice_id, asset(10000000)); transfer(account_id_type(), bob_id, asset(10000000)); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); fc::optional name = internationalized_string_type({{"en", "Washington Capitals vs. Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホーク"}}); fc::optional season = internationalized_string_type({{"en", "2017-18"}}); - update_event(capitals_vs_blackhawks.id, _name = name); - update_event(capitals_vs_blackhawks.id, _season = season); - update_event(capitals_vs_blackhawks.id, _name = name, _season = season); + update_event(capitals_vs_blackhawks_id, _name = name); + update_event(capitals_vs_blackhawks_id, _season = season); + update_event(capitals_vs_blackhawks_id, _name = name, _season = season); const sport_object& ice_on_hockey = create_sport({{"en", "Hockey on Ice"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); const event_group_object& nhl2 = create_event_group({{"en", "NHL2"}, {"zh_Hans", "國家冰球聯盟"}, {"ja", "ナショナルホッケーリーグ"}}, ice_on_hockey.id); - update_event(capitals_vs_blackhawks.id, _event_group_id = nhl2.id); + update_event(capitals_vs_blackhawks_id, _event_group_id = nhl2.id); - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); // caps win - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); @@ -1946,12 +1825,12 @@ BOOST_AUTO_TEST_CASE(betting_market_rules_update_test) fc::optional name = internationalized_string_type({{"en", "NHL Rules v1.1"}}); fc::optional desc = internationalized_string_type({{"en", "The winner will be the team with the most points at the end of the game. The team with fewer points will not be the winner."}}); - update_betting_market_rules(betting_market_rules.id, name, empty); - update_betting_market_rules(betting_market_rules.id, empty, desc); - update_betting_market_rules(betting_market_rules.id, name, desc); + update_betting_market_rules(betting_market_rules_id, name, empty); + update_betting_market_rules(betting_market_rules_id, empty, desc); + update_betting_market_rules(betting_market_rules_id, name, desc); transfer(account_id_type(), alice_id, asset(10000000)); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); @@ -1966,28 +1845,28 @@ BOOST_AUTO_TEST_CASE(betting_market_group_update_test) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); transfer(account_id_type(), alice_id, asset(10000000)); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); internationalized_string_type new_description = internationalized_string_type({{"en", "Money line"}}); const betting_market_rules_object& new_betting_market_rules = create_betting_market_rules({{"en", "NHL Rules v2.0"}}, {{"en", "The winner will be the team with the most points at the end of the game. The team with fewer points will not be the winner."}}); fc::optional new_rule = new_betting_market_rules.id; - update_betting_market_group(moneyline_betting_markets.id, _description = new_description); - update_betting_market_group(moneyline_betting_markets.id, _rules_id = new_betting_market_rules.id); - update_betting_market_group(moneyline_betting_markets.id, _description = new_description, _rules_id = new_betting_market_rules.id); + update_betting_market_group(moneyline_betting_markets_id, _description = new_description); + update_betting_market_group(moneyline_betting_markets_id, _rules_id = new_betting_market_rules.id); + update_betting_market_group(moneyline_betting_markets_id, _description = new_description, _rules_id = new_betting_market_rules.id); transfer(account_id_type(), bob_id, asset(10000000)); - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); // caps win - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); @@ -2008,24 +1887,24 @@ BOOST_AUTO_TEST_CASE(betting_market_update_test) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); transfer(account_id_type(), alice_id, asset(10000000)); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); fc::optional payout_condition = internationalized_string_type({{"en", "Washington Capitals lose"}}); // update the payout condition - update_betting_market(capitals_win_market.id, fc::optional(), payout_condition); + update_betting_market(capitals_win_market_id, fc::optional(), payout_condition); transfer(account_id_type(), bob_id, asset(10000000)); - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); // caps win - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); uint16_t rake_fee_percentage = db.get_global_properties().parameters.betting_rake_fee_percentage(); @@ -2052,27 +1931,25 @@ BOOST_AUTO_TEST_CASE(event_driven_standard_progression_1) { CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); graphene::bookie::bookie_api bookie_api(app); - // save the event id for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading betting market"); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); // as soon as a block is generated, the betting market group will settle, and the market @@ -2096,40 +1973,33 @@ BOOST_AUTO_TEST_CASE(event_driven_standard_progression_1_with_delay) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 60 /* seconds */); graphene::bookie::bookie_api bookie_api(app); - // save the ids for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; - betting_market_group_id_type moneyline_betting_markets_id = moneyline_betting_markets.id; - betting_market_id_type capitals_win_market_id = capitals_win_market.id; - betting_market_id_type blackhawks_win_market_id = blackhawks_win_market.id; - - BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading betting market"); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); // it should be waiting 60 seconds before it settles - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::graded); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::graded); - BOOST_CHECK(capitals_win_market.resolution == betting_market_resolution_type::win); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::graded); - BOOST_CHECK(blackhawks_win_market.resolution == betting_market_resolution_type::not_win); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::graded); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::graded); + BOOST_CHECK(capitals_win_market_id(db).resolution == betting_market_resolution_type::win); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::graded); + BOOST_CHECK(blackhawks_win_market_id(db).resolution == betting_market_resolution_type::not_win); generate_blocks(60); // as soon as a block is generated, the betting market group will settle, and the market @@ -2167,65 +2037,63 @@ BOOST_AUTO_TEST_CASE(event_driven_standard_progression_2) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); graphene::bookie::bookie_api bookie_api(app); - // save the event id for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event frozen"); - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); BOOST_TEST_MESSAGE("setting the event back to upcoming"); - update_event(capitals_vs_blackhawks.id, _status = event_status::upcoming); + update_event(capitals_vs_blackhawks_id, _status = event_status::upcoming); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event in-progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); BOOST_TEST_MESSAGE("setting the event frozen"); - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); BOOST_TEST_MESSAGE("setting the event back in-progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading betting market"); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); // as soon as a block is generated, the betting market group will settle, and the market @@ -2255,65 +2123,63 @@ BOOST_AUTO_TEST_CASE(event_driven_standard_progression_2_never_in_play) CREATE_ICE_HOCKEY_BETTING_MARKET(true, 0); graphene::bookie::bookie_api bookie_api(app); - // save the event id for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event frozen"); - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); BOOST_TEST_MESSAGE("setting the event back to upcoming"); - update_event(capitals_vs_blackhawks.id, _status = event_status::upcoming); + update_event(capitals_vs_blackhawks_id, _status = event_status::upcoming); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event in-progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); BOOST_TEST_MESSAGE("setting the event frozen"); - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); BOOST_TEST_MESSAGE("setting the event back in-progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading betting market"); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); // as soon as a block is generated, the betting market group will settle, and the market @@ -2341,55 +2207,53 @@ BOOST_AUTO_TEST_CASE(event_driven_standard_progression_3) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); graphene::bookie::bookie_api bookie_api(app); - // save the event id for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event frozen"); - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); BOOST_TEST_MESSAGE("setting the event in progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); BOOST_TEST_MESSAGE("setting the event frozen"); - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); BOOST_TEST_MESSAGE("setting the event back in-progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event to canceled"); - update_event(capitals_vs_blackhawks.id, _status = event_status::canceled); + update_event(capitals_vs_blackhawks_id, _status = event_status::canceled); generate_blocks(1); // as soon as a block is generated, the betting market group will cancel, and the market @@ -2414,80 +2278,78 @@ BOOST_AUTO_TEST_CASE(event_driven_progression_errors_1) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); graphene::bookie::bookie_api bookie_api(app); - // save the event id for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_REQUIRE(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_REQUIRE(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_REQUIRE(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_REQUIRE(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_REQUIRE(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_REQUIRE(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_REQUIRE(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_REQUIRE(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); // settled is the only illegal transition from upcoming BOOST_TEST_MESSAGE("verifying we can't jump to settled"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::settled, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::settled, _force = true), fc::exception); BOOST_TEST_MESSAGE("setting the event frozen"); - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_REQUIRE(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_REQUIRE(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_REQUIRE(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_REQUIRE(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_REQUIRE(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_REQUIRE(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_REQUIRE(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_REQUIRE(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); // settled is the only illegal transition from this frozen event BOOST_TEST_MESSAGE("verifying we can't jump to settled"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::settled, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::settled, _force = true), fc::exception); BOOST_TEST_MESSAGE("setting the event in progress"); - update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress); + update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress); generate_blocks(1); - BOOST_REQUIRE(capitals_vs_blackhawks.get_status() == event_status::in_progress); - BOOST_REQUIRE(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); + BOOST_REQUIRE(capitals_vs_blackhawks_id(db).get_status() == event_status::in_progress); + BOOST_REQUIRE(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); // we can't go back to upcoming from in_progress. // settled is disallowed everywhere BOOST_TEST_MESSAGE("verifying we can't jump to upcoming"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::upcoming, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::upcoming, _force = true), fc::exception); BOOST_TEST_MESSAGE("verifying we can't jump to settled"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::settled, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::settled, _force = true), fc::exception); BOOST_TEST_MESSAGE("setting the event frozen"); - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_REQUIRE(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_REQUIRE(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_REQUIRE(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_REQUIRE(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_REQUIRE(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_REQUIRE(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_REQUIRE(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_REQUIRE(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); // we can't go back to upcoming from frozen once we've gone in_progress. // settled is disallowed everywhere BOOST_TEST_MESSAGE("verifying we can't jump to upcoming"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::upcoming, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::upcoming, _force = true), fc::exception); BOOST_TEST_MESSAGE("verifying we can't jump to settled"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::settled, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::settled, _force = true), fc::exception); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_REQUIRE(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_REQUIRE(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_REQUIRE(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_REQUIRE(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_REQUIRE(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_REQUIRE(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_REQUIRE(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_REQUIRE(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); // we can't go back to upcoming, in_progress, or frozen once we're finished. // settled is disallowed everywhere BOOST_TEST_MESSAGE("verifying we can't jump to upcoming"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::upcoming, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::upcoming, _force = true), fc::exception); BOOST_TEST_MESSAGE("verifying we can't jump to in_progress"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::in_progress, _force = true), fc::exception); BOOST_TEST_MESSAGE("verifying we can't jump to frozen"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::frozen, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::frozen, _force = true), fc::exception); BOOST_TEST_MESSAGE("verifying we can't jump to settled"); - BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks.id, _status = event_status::settled, _force = true), fc::exception); + BOOST_CHECK_THROW(update_event(capitals_vs_blackhawks_id, _status = event_status::settled, _force = true), fc::exception); BOOST_TEST_MESSAGE("setting the event to canceled"); - update_event(capitals_vs_blackhawks.id, _status = event_status::canceled); + update_event(capitals_vs_blackhawks_id, _status = event_status::canceled); generate_blocks(1); fc::variants objects_from_bookie = bookie_api.get_objects({capitals_vs_blackhawks_id}); @@ -2517,27 +2379,25 @@ BOOST_AUTO_TEST_CASE(event_driven_progression_errors_2) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); graphene::bookie::bookie_api bookie_api(app); - // save the event id for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_REQUIRE(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_REQUIRE(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_REQUIRE(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_REQUIRE(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_REQUIRE(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_REQUIRE(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_REQUIRE(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_REQUIRE(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting the event to finished"); - update_event(capitals_vs_blackhawks.id, _status = event_status::finished); + update_event(capitals_vs_blackhawks_id, _status = event_status::finished); generate_blocks(1); - BOOST_REQUIRE(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_REQUIRE(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_REQUIRE(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_REQUIRE(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_REQUIRE(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_REQUIRE(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_REQUIRE(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_REQUIRE(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading betting market"); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); // as soon as a block is generated, the betting market group will settle, and the market @@ -2569,47 +2429,45 @@ BOOST_AUTO_TEST_CASE(betting_market_group_driven_standard_progression) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); graphene::bookie::bookie_api bookie_api(app); - // save the event id for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("setting betting market to frozen"); // the event should stay in the upcoming state - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::frozen); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::frozen); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); BOOST_TEST_MESSAGE("setting the event frozen"); // this should only change the status of the event, just verify that nothing weird happens when // we try to set the bmg to frozen when it's already frozen - update_event(capitals_vs_blackhawks.id, _status = event_status::frozen); + update_event(capitals_vs_blackhawks_id, _status = event_status::frozen); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::frozen); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::frozen); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::frozen); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::frozen); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::frozen); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::frozen); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::frozen); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::frozen); BOOST_TEST_MESSAGE("setting betting market to closed"); // the event should go to finished automatically - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading betting market"); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); // as soon as a block is generated, the betting market group will settle, and the market @@ -2628,99 +2486,97 @@ BOOST_AUTO_TEST_CASE(multi_betting_market_group_driven_standard_progression) CREATE_EXTENDED_ICE_HOCKEY_BETTING_MARKET(false, 0); graphene::bookie::bookie_api bookie_api(app); - // save the event id for checking after it is deleted - event_id_type capitals_vs_blackhawks_id = capitals_vs_blackhawks.id; BOOST_TEST_MESSAGE("verify everything is in the correct initial state"); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(first_period_result_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(first_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(first_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(second_period_result_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(second_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(second_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(third_period_result_betting_markets.get_status() == betting_market_group_status::upcoming); - BOOST_CHECK(third_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(third_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(first_period_result_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(first_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(first_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(second_period_result_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(second_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(second_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(third_period_result_betting_markets_id(db).get_status() == betting_market_group_status::upcoming); + BOOST_CHECK(third_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(third_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("the game is starting, setting the main betting market and the first period to in_play"); // the event should stay in the upcoming state - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::in_play); - update_betting_market_group(first_period_result_betting_markets.id, _status = betting_market_group_status::in_play); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::in_play); + update_betting_market_group(first_period_result_betting_markets_id, _status = betting_market_group_status::in_play); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(first_period_result_betting_markets.get_status() == betting_market_group_status::in_play); - BOOST_CHECK(first_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(first_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(first_period_result_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_CHECK(first_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(first_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("the first period is over, starting the second period"); - update_betting_market_group(first_period_result_betting_markets.id, _status = betting_market_group_status::closed); - update_betting_market_group(second_period_result_betting_markets.id, _status = betting_market_group_status::in_play); + update_betting_market_group(first_period_result_betting_markets_id, _status = betting_market_group_status::closed); + update_betting_market_group(second_period_result_betting_markets_id, _status = betting_market_group_status::in_play); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(first_period_result_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(first_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(first_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(second_period_result_betting_markets.get_status() == betting_market_group_status::in_play); - BOOST_CHECK(second_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(second_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(first_period_result_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(first_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(first_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(second_period_result_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_CHECK(second_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(second_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading the first period market"); - resolve_betting_market_group(first_period_result_betting_markets.id, - {{first_period_capitals_win_market.id, betting_market_resolution_type::win}, - {first_period_blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(first_period_result_betting_markets_id, + {{first_period_capitals_win_market_id, betting_market_resolution_type::win}, + {first_period_blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); BOOST_TEST_MESSAGE("the second period is over, starting the third period"); - update_betting_market_group(second_period_result_betting_markets.id, _status = betting_market_group_status::closed); - update_betting_market_group(third_period_result_betting_markets.id, _status = betting_market_group_status::in_play); + update_betting_market_group(second_period_result_betting_markets_id, _status = betting_market_group_status::closed); + update_betting_market_group(third_period_result_betting_markets_id, _status = betting_market_group_status::in_play); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::upcoming); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(second_period_result_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(second_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(second_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(third_period_result_betting_markets.get_status() == betting_market_group_status::in_play); - BOOST_CHECK(third_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(third_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(second_period_result_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(second_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(second_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(third_period_result_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_CHECK(third_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(third_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading the second period market"); - resolve_betting_market_group(second_period_result_betting_markets.id, - {{second_period_capitals_win_market.id, betting_market_resolution_type::win}, - {second_period_blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(second_period_result_betting_markets_id, + {{second_period_capitals_win_market_id, betting_market_resolution_type::win}, + {second_period_blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); BOOST_TEST_MESSAGE("the game is over, closing 3rd period and game"); - update_betting_market_group(third_period_result_betting_markets.id, _status = betting_market_group_status::closed); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(third_period_result_betting_markets_id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); generate_blocks(1); - BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished); - BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(third_period_result_betting_markets.get_status() == betting_market_group_status::closed); - BOOST_CHECK(third_period_capitals_win_market.get_status() == betting_market_status::unresolved); - BOOST_CHECK(third_period_blackhawks_win_market.get_status() == betting_market_status::unresolved); + BOOST_CHECK(capitals_vs_blackhawks_id(db).get_status() == event_status::finished); + BOOST_CHECK(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(third_period_result_betting_markets_id(db).get_status() == betting_market_group_status::closed); + BOOST_CHECK(third_period_capitals_win_market_id(db).get_status() == betting_market_status::unresolved); + BOOST_CHECK(third_period_blackhawks_win_market_id(db).get_status() == betting_market_status::unresolved); BOOST_TEST_MESSAGE("grading the third period and game"); - resolve_betting_market_group(third_period_result_betting_markets.id, - {{third_period_capitals_win_market.id, betting_market_resolution_type::win}, - {third_period_blackhawks_win_market.id, betting_market_resolution_type::not_win}}); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(third_period_result_betting_markets_id, + {{third_period_capitals_win_market_id, betting_market_resolution_type::win}, + {third_period_blackhawks_win_market_id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); // as soon as a block is generated, the two betting market groups will settle, and the market @@ -2769,47 +2625,47 @@ BOOST_FIXTURE_TEST_CASE( another_event_group_update_test, database_fixture) transfer(account_id_type(), alice_id, asset(10000000)); transfer(account_id_type(), bob_id, asset(10000000)); - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); fc::optional name = internationalized_string_type({{"en", "IBM"}, {"zh_Hans", "國家冰球聯"}, {"ja", "ナショナルホッケーリー"}}); const sport_object& ice_on_hockey = create_sport({{"en", "Hockey on Ice"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); \ fc::optional sport_id = ice_on_hockey.id; - update_event_group(nhl.id, fc::optional(), name); - update_event_group(nhl.id, sport_id, fc::optional()); - update_event_group(nhl.id, sport_id, name); + update_event_group(nhl_id, fc::optional(), name); + update_event_group(nhl_id, sport_id, fc::optional()); + update_event_group(nhl_id, sport_id, name); //Disabling the below 4 TRY_EXPECT_THROW lines to not throw anything beacuse functioning as expected // trx_state->_is_proposed_trx - //GRAPHENE_REQUIRE_THROW(try_update_event_group(nhl.id, fc::optional(), fc::optional(), true), fc::exception); - // TRY_EXPECT_THROW(try_update_event_group(nhl.id, fc::optional(), fc::optional(), true), fc::exception, "_is_proposed_trx"); + //GRAPHENE_REQUIRE_THROW(try_update_event_group(nhl_id, fc::optional(), fc::optional(), true), fc::exception); + // TRY_EXPECT_THROW(try_update_event_group(nhl_id, fc::optional(), fc::optional(), true), fc::exception, "_is_proposed_trx"); // #! nothing to change - //GRAPHENE_REQUIRE_THROW(try_update_event_group(nhl.id, fc::optional(), fc::optional()), fc::exception); - //TRY_EXPECT_THROW(try_update_event_group(nhl.id, fc::optional(), fc::optional()), fc::exception, "nothing to change"); + //GRAPHENE_REQUIRE_THROW(try_update_event_group(nhl_id, fc::optional(), fc::optional()), fc::exception); + //TRY_EXPECT_THROW(try_update_event_group(nhl_id, fc::optional(), fc::optional()), fc::exception, "nothing to change"); // #! sport_id must refer to a sport_id_type - sport_id = capitals_win_market.id; - //GRAPHENE_REQUIRE_THROW(try_update_event_group(nhl.id, sport_id, fc::optional()), fc::exception); - //TRY_EXPECT_THROW(try_update_event_group(nhl.id, sport_id, fc::optional()), fc::exception, "sport_id must refer to a sport_id_type"); + sport_id = capitals_win_market_id; + //GRAPHENE_REQUIRE_THROW(try_update_event_group(nhl_id, sport_id, fc::optional()), fc::exception); + //TRY_EXPECT_THROW(try_update_event_group(nhl_id, sport_id, fc::optional()), fc::exception, "sport_id must refer to a sport_id_type"); // #! invalid sport specified sport_id = sport_id_type(13); - //GRAPHENE_REQUIRE_THROW(try_update_event_group(nhl.id, sport_id, fc::optional()), fc::exception); - //TRY_EXPECT_THROW(try_update_event_group(nhl.id, sport_id, fc::optional()), fc::exception, "invalid sport specified"); + //GRAPHENE_REQUIRE_THROW(try_update_event_group(nhl_id, sport_id, fc::optional()), fc::exception); + //TRY_EXPECT_THROW(try_update_event_group(nhl_id, sport_id, fc::optional()), fc::exception, "invalid sport specified"); - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000); - update_betting_market_group(moneyline_betting_markets.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, _status = betting_market_group_status::closed); // caps win - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); uint16_t rake_fee_percentage = db.get_global_properties().parameters.betting_rake_fee_percentage(); @@ -2837,31 +2693,31 @@ BOOST_AUTO_TEST_CASE( wimbledon_2017_gentelmen_singles_sf_test ) transfer(account_id_type(), alice_id, asset(10000000)); transfer(account_id_type(), bob_id, asset(10000000)); - BOOST_TEST_MESSAGE("moneyline_berdych_vs_federer " << fc::variant(moneyline_berdych_vs_federer.id, 1).as(1)); - BOOST_TEST_MESSAGE("moneyline_cilic_vs_querrey " << fc::variant(moneyline_cilic_vs_querrey.id, 1).as(1)); + BOOST_TEST_MESSAGE("moneyline_berdych_vs_federer " << fc::variant(moneyline_berdych_vs_federer_id, 1).as(1)); + BOOST_TEST_MESSAGE("moneyline_cilic_vs_querrey " << fc::variant(moneyline_cilic_vs_querrey_id, 1).as(1)); - BOOST_TEST_MESSAGE("berdych_wins_market " << fc::variant(berdych_wins_market.id, 1).as(1)); - BOOST_TEST_MESSAGE("federer_wins_market " << fc::variant(federer_wins_market.id, 1).as(1)); - BOOST_TEST_MESSAGE("cilic_wins_market " << fc::variant(cilic_wins_market.id, 1).as(1)); - BOOST_TEST_MESSAGE("querrey_wins_market " << fc::variant(querrey_wins_market.id, 1).as(1)); + BOOST_TEST_MESSAGE("berdych_wins_market " << fc::variant(berdych_wins_market_id, 1).as(1)); + BOOST_TEST_MESSAGE("federer_wins_market " << fc::variant(federer_wins_market_id, 1).as(1)); + BOOST_TEST_MESSAGE("cilic_wins_market " << fc::variant(cilic_wins_market_id, 1).as(1)); + BOOST_TEST_MESSAGE("querrey_wins_market " << fc::variant(querrey_wins_market_id, 1).as(1)); - place_bet(alice_id, berdych_wins_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(bob_id, berdych_wins_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, berdych_wins_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, berdych_wins_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000); - place_bet(alice_id, cilic_wins_market.id, bet_type::back, asset(100000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(bob_id, cilic_wins_market.id, bet_type::lay, asset(100000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, cilic_wins_market_id, bet_type::back, asset(100000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, cilic_wins_market_id, bet_type::lay, asset(100000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000 - 100000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000 - 100000); - update_betting_market_group(moneyline_berdych_vs_federer.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_berdych_vs_federer_id, _status = betting_market_group_status::closed); // federer wins - resolve_betting_market_group(moneyline_berdych_vs_federer.id, - {{berdych_wins_market.id, betting_market_resolution_type::not_win}, - {federer_wins_market.id, betting_market_resolution_type::win}}); + resolve_betting_market_group(moneyline_berdych_vs_federer_id, + {{berdych_wins_market_id, betting_market_resolution_type::not_win}, + {federer_wins_market_id, betting_market_resolution_type::win}}); generate_blocks(1); uint32_t bob_rake_value = (-1000000 + 2000000) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100; @@ -2870,11 +2726,11 @@ BOOST_AUTO_TEST_CASE( wimbledon_2017_gentelmen_singles_sf_test ) BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000 - 100000); BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000 - 100000 + 2000000 - bob_rake_value); - update_betting_market_group(moneyline_cilic_vs_querrey.id, _status = betting_market_group_status::closed); + update_betting_market_group(moneyline_cilic_vs_querrey_id, _status = betting_market_group_status::closed); // cilic wins - resolve_betting_market_group(moneyline_cilic_vs_querrey.id, - {{cilic_wins_market.id, betting_market_resolution_type::win}, - {querrey_wins_market.id, betting_market_resolution_type::not_win}}); + resolve_betting_market_group(moneyline_cilic_vs_querrey_id, + {{cilic_wins_market_id, betting_market_resolution_type::win}, + {querrey_wins_market_id, betting_market_resolution_type::not_win}}); generate_blocks(1); uint32_t alice_rake_value = (-100000 + 200000) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100; @@ -2898,21 +2754,17 @@ BOOST_AUTO_TEST_CASE( wimbledon_2017_gentelmen_singles_final_test ) transfer(account_id_type(), alice_id, asset(10000000)); transfer(account_id_type(), bob_id, asset(10000000)); - BOOST_TEST_MESSAGE("moneyline_cilic_vs_federer " << fc::variant(moneyline_cilic_vs_federer.id, 1).as(1)); + BOOST_TEST_MESSAGE("moneyline_cilic_vs_federer " << fc::variant(moneyline_cilic_vs_federer_id, 1).as(1)); - BOOST_TEST_MESSAGE("federer_wins_final_market " << fc::variant(federer_wins_final_market.id, 1).as(1)); - BOOST_TEST_MESSAGE("cilic_wins_final_market " << fc::variant(cilic_wins_final_market.id, 1).as(1)); + BOOST_TEST_MESSAGE("federer_wins_final_market " << fc::variant(federer_wins_final_market_id, 1).as(1)); + BOOST_TEST_MESSAGE("cilic_wins_final_market " << fc::variant(cilic_wins_final_market_id, 1).as(1)); - betting_market_group_id_type moneyline_cilic_vs_federer_id = moneyline_cilic_vs_federer.id; update_betting_market_group(moneyline_cilic_vs_federer_id, _status = betting_market_group_status::in_play); - place_bet(alice_id, cilic_wins_final_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(bob_id, cilic_wins_final_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, cilic_wins_final_market_id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, cilic_wins_final_market_id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - auto cilic_wins_final_market_id = cilic_wins_final_market.id; - auto federer_wins_final_market_id = federer_wins_final_market.id; - - update_event(cilic_vs_federer.id, _name = internationalized_string_type({{"en", "R. Federer vs. M. Cilic"}})); + update_event(cilic_vs_federer_id, _name = internationalized_string_type({{"en", "R. Federer vs. M. Cilic"}})); generate_blocks(13); diff --git a/tests/common/betting_test_markets.hpp b/tests/common/betting_test_markets.hpp index f67dc067..e774267b 100644 --- a/tests/common/betting_test_markets.hpp +++ b/tests/common/betting_test_markets.hpp @@ -33,110 +33,110 @@ using namespace graphene::chain; #define CREATE_ICE_HOCKEY_BETTING_MARKET(never_in_play, delay_before_settling) \ create_sport({{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); \ generate_blocks(1); \ - const sport_object& ice_hockey = *db.get_index_type().indices().get().rbegin(); \ - create_event_group({{"en", "NHL"}, {"zh_Hans", "國家冰球聯盟"}, {"ja", "ナショナルホッケーリーグ"}}, ice_hockey.id); \ + const sport_id_type ice_hockey_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_event_group({{"en", "NHL"}, {"zh_Hans", "國家冰球聯盟"}, {"ja", "ナショナルホッケーリーグ"}}, ice_hockey_id); \ generate_blocks(1); \ - const event_group_object& nhl = *db.get_index_type().indices().get().rbegin(); \ - create_event({{"en", "Washington Capitals/Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑鷹"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホークス"}}, {{"en", "2016-17"}}, nhl.id); \ + const event_group_id_type nhl_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_event({{"en", "Washington Capitals/Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑鷹"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホークス"}}, {{"en", "2016-17"}}, nhl_id); \ generate_blocks(1); \ - const event_object& capitals_vs_blackhawks = *db.get_index_type().indices().get().rbegin(); \ + const event_id_type capitals_vs_blackhawks_id = (*db.get_index_type().indices().get().rbegin()).id; \ create_betting_market_rules({{"en", "NHL Rules v1.0"}}, {{"en", "The winner will be the team with the most points at the end of the game. The team with fewer points will not be the winner."}}); \ generate_blocks(1); \ - const betting_market_rules_object& betting_market_rules = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), never_in_play, delay_before_settling); \ + const betting_market_rules_id_type betting_market_rules_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market_group({{"en", "Moneyline"}}, capitals_vs_blackhawks_id, betting_market_rules_id, asset_id_type(), never_in_play, delay_before_settling); \ generate_blocks(1); \ - const betting_market_group_object& moneyline_betting_markets = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_betting_markets.id, {{"en", "Washington Capitals win"}}); \ + const betting_market_group_id_type moneyline_betting_markets_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(moneyline_betting_markets_id, {{"en", "Washington Capitals win"}}); \ generate_blocks(1); \ - const betting_market_object& capitals_win_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_betting_markets.id, {{"en", "Chicago Blackhawks win"}}); \ + const betting_market_id_type capitals_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(moneyline_betting_markets_id, {{"en", "Chicago Blackhawks win"}}); \ generate_blocks(1); \ - const betting_market_object& blackhawks_win_market = *db.get_index_type().indices().get().rbegin(); \ - (void)capitals_win_market; (void)blackhawks_win_market; + const betting_market_id_type& blackhawks_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + (void)capitals_win_market_id; (void)blackhawks_win_market_id; // create the basic betting market, plus groups for the first, second, and third period results #define CREATE_EXTENDED_ICE_HOCKEY_BETTING_MARKET(never_in_play, delay_before_settling) \ CREATE_ICE_HOCKEY_BETTING_MARKET(never_in_play, delay_before_settling) \ - create_betting_market_group({{"en", "First Period Result"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), never_in_play, delay_before_settling); \ + create_betting_market_group({{"en", "First Period Result"}}, capitals_vs_blackhawks_id, betting_market_rules_id, asset_id_type(), never_in_play, delay_before_settling); \ generate_blocks(1); \ - const betting_market_group_object& first_period_result_betting_markets = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(first_period_result_betting_markets.id, {{"en", "Washington Capitals win"}}); \ + const betting_market_group_id_type first_period_result_betting_markets_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(first_period_result_betting_markets_id, {{"en", "Washington Capitals win"}}); \ generate_blocks(1); \ - const betting_market_object& first_period_capitals_win_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(first_period_result_betting_markets.id, {{"en", "Chicago Blackhawks win"}}); \ + const betting_market_id_type first_period_capitals_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(first_period_result_betting_markets_id, {{"en", "Chicago Blackhawks win"}}); \ generate_blocks(1); \ - const betting_market_object& first_period_blackhawks_win_market = *db.get_index_type().indices().get().rbegin(); \ - (void)first_period_capitals_win_market; (void)first_period_blackhawks_win_market; \ + const betting_market_id_type first_period_blackhawks_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + (void)first_period_capitals_win_market_id; (void)first_period_blackhawks_win_market_id; \ \ - create_betting_market_group({{"en", "Second Period Result"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), never_in_play, delay_before_settling); \ + create_betting_market_group({{"en", "Second Period Result"}}, capitals_vs_blackhawks_id, betting_market_rules_id, asset_id_type(), never_in_play, delay_before_settling); \ generate_blocks(1); \ - const betting_market_group_object& second_period_result_betting_markets = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(second_period_result_betting_markets.id, {{"en", "Washington Capitals win"}}); \ + const betting_market_group_id_type second_period_result_betting_markets_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(second_period_result_betting_markets_id, {{"en", "Washington Capitals win"}}); \ generate_blocks(1); \ - const betting_market_object& second_period_capitals_win_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(second_period_result_betting_markets.id, {{"en", "Chicago Blackhawks win"}}); \ + const betting_market_id_type second_period_capitals_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(second_period_result_betting_markets_id, {{"en", "Chicago Blackhawks win"}}); \ generate_blocks(1); \ - const betting_market_object& second_period_blackhawks_win_market = *db.get_index_type().indices().get().rbegin(); \ - (void)second_period_capitals_win_market; (void)second_period_blackhawks_win_market; \ + const betting_market_id_type second_period_blackhawks_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + (void)second_period_capitals_win_market_id; (void)second_period_blackhawks_win_market_id; \ \ - create_betting_market_group({{"en", "Third Period Result"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), never_in_play, delay_before_settling); \ + create_betting_market_group({{"en", "Third Period Result"}}, capitals_vs_blackhawks_id, betting_market_rules_id, asset_id_type(), never_in_play, delay_before_settling); \ generate_blocks(1); \ - const betting_market_group_object& third_period_result_betting_markets = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(third_period_result_betting_markets.id, {{"en", "Washington Capitals win"}}); \ + const betting_market_group_id_type third_period_result_betting_markets_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(third_period_result_betting_markets_id, {{"en", "Washington Capitals win"}}); \ generate_blocks(1); \ - const betting_market_object& third_period_capitals_win_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(third_period_result_betting_markets.id, {{"en", "Chicago Blackhawks win"}}); \ + const betting_market_id_type third_period_capitals_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(third_period_result_betting_markets_id, {{"en", "Chicago Blackhawks win"}}); \ generate_blocks(1); \ - const betting_market_object& third_period_blackhawks_win_market = *db.get_index_type().indices().get().rbegin(); \ - (void)third_period_capitals_win_market; (void)third_period_blackhawks_win_market; + const betting_market_id_type third_period_blackhawks_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + (void)third_period_capitals_win_market_id; (void)third_period_blackhawks_win_market_id; #define CREATE_TENNIS_BETTING_MARKET() \ create_betting_market_rules({{"en", "Tennis Rules v1.0"}}, {{"en", "The winner is the player who wins the last ball in the match."}}); \ generate_blocks(1); \ - const betting_market_rules_object& tennis_rules = *db.get_index_type().indices().get().rbegin(); \ + const betting_market_rules_id_type tennis_rules_id = (*db.get_index_type().indices().get().rbegin()).id; \ create_sport({{"en", "Tennis"}}); \ generate_blocks(1); \ - const sport_object& tennis = *db.get_index_type().indices().get().rbegin(); \ - create_event_group({{"en", "Wimbledon"}}, tennis.id); \ + const sport_id_type tennis_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_event_group({{"en", "Wimbledon"}}, tennis_id); \ generate_blocks(1); \ - const event_group_object& wimbledon = *db.get_index_type().indices().get().rbegin(); \ - create_event({{"en", "R. Federer/T. Berdych"}}, {{"en", "2017"}}, wimbledon.id); \ + const event_group_id_type wimbledon_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_event({{"en", "R. Federer/T. Berdych"}}, {{"en", "2017"}}, wimbledon_id); \ generate_blocks(1); \ - const event_object& berdych_vs_federer = *db.get_index_type().indices().get().rbegin(); \ - create_event({{"en", "M. Cilic/S. Querrye"}}, {{"en", "2017"}}, wimbledon.id); \ + const event_id_type berdych_vs_federer_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_event({{"en", "M. Cilic/S. Querrye"}}, {{"en", "2017"}}, wimbledon_id); \ generate_blocks(1); \ - const event_object& cilic_vs_querrey = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline 1st sf"}}, berdych_vs_federer.id, tennis_rules.id, asset_id_type(), false, 0); \ + const event_id_type& cilic_vs_querrey_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market_group({{"en", "Moneyline 1st sf"}}, berdych_vs_federer_id, tennis_rules_id, asset_id_type(), false, 0); \ generate_blocks(1); \ - const betting_market_group_object& moneyline_berdych_vs_federer = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline 2nd sf"}}, cilic_vs_querrey.id, tennis_rules.id, asset_id_type(), false, 0); \ + const betting_market_group_id_type moneyline_berdych_vs_federer_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market_group({{"en", "Moneyline 2nd sf"}}, cilic_vs_querrey_id, tennis_rules_id, asset_id_type(), false, 0); \ generate_blocks(1); \ - const betting_market_group_object& moneyline_cilic_vs_querrey = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_berdych_vs_federer.id, {{"en", "T. Berdych defeats R. Federer"}}); \ + const betting_market_group_id_type moneyline_cilic_vs_querrey_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(moneyline_berdych_vs_federer_id, {{"en", "T. Berdych defeats R. Federer"}}); \ generate_blocks(1); \ - const betting_market_object& berdych_wins_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_berdych_vs_federer.id, {{"en", "R. Federer defeats T. Berdych"}}); \ + const betting_market_id_type berdych_wins_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(moneyline_berdych_vs_federer_id, {{"en", "R. Federer defeats T. Berdych"}}); \ generate_blocks(1); \ - const betting_market_object& federer_wins_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_cilic_vs_querrey.id, {{"en", "M. Cilic defeats S. Querrey"}}); \ + const betting_market_id_type federer_wins_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(moneyline_cilic_vs_querrey_id, {{"en", "M. Cilic defeats S. Querrey"}}); \ generate_blocks(1); \ - const betting_market_object& cilic_wins_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_cilic_vs_querrey.id, {{"en", "S. Querrey defeats M. Cilic"}});\ + const betting_market_id_type cilic_wins_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(moneyline_cilic_vs_querrey_id, {{"en", "S. Querrey defeats M. Cilic"}});\ generate_blocks(1); \ - const betting_market_object& querrey_wins_market = *db.get_index_type().indices().get().rbegin(); \ - create_event({{"en", "R. Federer/M. Cilic"}}, {{"en", "2017"}}, wimbledon.id); \ + const betting_market_id_type querrey_wins_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_event({{"en", "R. Federer/M. Cilic"}}, {{"en", "2017"}}, wimbledon_id); \ generate_blocks(1); \ - const event_object& cilic_vs_federer = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline final"}}, cilic_vs_federer.id, tennis_rules.id, asset_id_type(), false, 0); \ + const event_id_type& cilic_vs_federer_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market_group({{"en", "Moneyline final"}}, cilic_vs_federer_id, tennis_rules_id, asset_id_type(), false, 0); \ generate_blocks(1); \ - const betting_market_group_object& moneyline_cilic_vs_federer = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_cilic_vs_federer.id, {{"en", "R. Federer defeats M. Cilic"}}); \ + const betting_market_group_id_type moneyline_cilic_vs_federer_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(moneyline_cilic_vs_federer_id, {{"en", "R. Federer defeats M. Cilic"}}); \ generate_blocks(1); \ - const betting_market_object& federer_wins_final_market = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market(moneyline_cilic_vs_federer.id, {{"en", "M. Cilic defeats R. Federer"}}); \ + const betting_market_id_type federer_wins_final_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market(moneyline_cilic_vs_federer_id, {{"en", "M. Cilic defeats R. Federer"}}); \ generate_blocks(1); \ - const betting_market_object& cilic_wins_final_market = *db.get_index_type().indices().get().rbegin(); \ - (void)federer_wins_market;(void)cilic_wins_market;(void)federer_wins_final_market; (void)cilic_wins_final_market; (void)berdych_wins_market; (void)querrey_wins_market; + const betting_market_id_type cilic_wins_final_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ + (void)federer_wins_market_id;(void)cilic_wins_market_id;(void)federer_wins_final_market_id; (void)cilic_wins_final_market_id; (void)berdych_wins_market_id; (void)querrey_wins_market_id; // set up a fixture that places a series of two matched bets, we'll use this fixture to verify // the result in all three possible outcomes @@ -155,19 +155,18 @@ struct simple_bet_test_fixture : database_fixture { transfer(account_id_type(), bob_id, asset(10000)); // place bets at 10:1 - place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(100, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::back, asset(100, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::lay, asset(1000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); // reverse positions at 1:1 - place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(1100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(1100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(alice_id, capitals_win_market_id, bet_type::lay, asset(1100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(bob_id, capitals_win_market_id, bet_type::back, asset(1100, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - capitals_win_betting_market_id = capitals_win_market.id; - blackhawks_win_betting_market_id = blackhawks_win_market.id; - moneyline_betting_markets_id = moneyline_betting_markets.id; + capitals_win_betting_market_id = capitals_win_market_id; + blackhawks_win_betting_market_id = blackhawks_win_market_id; // close betting to prepare for the next operation which will be grading or cancel - update_betting_market_group(moneyline_betting_markets.id, graphene::chain::keywords::_status = betting_market_group_status::closed); + update_betting_market_group(moneyline_betting_markets_id, graphene::chain::keywords::_status = betting_market_group_status::closed); generate_blocks(1); } }; diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 42fd6137..a88f0804 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -203,20 +204,28 @@ database_fixture::database_fixture() } database_fixture::~database_fixture() -{ try { - // If we're unwinding due to an exception, don't do any more checks. - // This way, boost test's last checkpoint tells us approximately where the error was. - if( !std::uncaught_exception() ) - { - verify_asset_supplies(db); - verify_account_history_plugin_index(); - BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); - } +{ + try { + // If we're unwinding due to an exception, don't do any more checks. + // This way, boost test's last checkpoint tells us approximately where the error was. + if( !std::uncaught_exception() ) + { + verify_asset_supplies(db); + verify_account_history_plugin_index(); + BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); + } - if( data_dir ) - db.close(); - return; -} FC_CAPTURE_AND_RETHROW() } + if( data_dir ) + db.close(); + return; + } catch (fc::exception& ex) { + BOOST_FAIL( std::string("fc::exception in ~database_fixture: ") + ex.to_detail_string() ); + } catch (std::exception& e) { + BOOST_FAIL( std::string("std::exception in ~database_fixture:") + e.what() ); + } catch (...) { + BOOST_FAIL( "Uncaught exception in ~database_fixture" ); + } +} fc::ecc::private_key database_fixture::generate_private_key(string seed) { @@ -327,6 +336,14 @@ void database_fixture::verify_asset_supplies( const database& db ) } } + for (const nft_metadata_object &o : db.get_index_type().indices()) + { + if (o.lottery_data) + { + total_balances[o.get_lottery_jackpot(db).asset_id] += o.get_lottery_jackpot(db).amount; + } + } + uint64_t sweeps_vestings = 0; for( const sweeps_vesting_balance_object& svbo: db.get_index_type< sweeps_vesting_balance_index >().indices() ) sweeps_vestings += svbo.balance; diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 366e707e..cd6ac185 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -127,7 +127,9 @@ extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; #define PREP_ACTOR(name) \ fc::ecc::private_key name ## _private_key = generate_private_key(BOOST_PP_STRINGIZE(name)); \ - public_key_type name ## _public_key = name ## _private_key.get_public_key(); + public_key_type name ## _public_key = name ## _private_key.get_public_key(); \ + (void) name ## _private_key; \ + (void) name ## _public_key; #define ACTOR(name) \ PREP_ACTOR(name) \ diff --git a/tests/generate_empty_blocks/CMakeLists.txt b/tests/generate_empty_blocks/CMakeLists.txt index af53ee91..5a585070 100644 --- a/tests/generate_empty_blocks/CMakeLists.txt +++ b/tests/generate_empty_blocks/CMakeLists.txt @@ -4,7 +4,7 @@ if( UNIX AND NOT APPLE ) endif() target_link_libraries( generate_empty_blocks - PRIVATE graphene_app graphene_chain graphene_egenesis_none fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_egenesis_none ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS generate_empty_blocks diff --git a/tests/peerplays_sidechain/bitcoin_transaction_tests.cpp b/tests/peerplays_sidechain/bitcoin_transaction_tests.cpp index 20fe878c..c749d790 100644 --- a/tests/peerplays_sidechain/bitcoin_transaction_tests.cpp +++ b/tests/peerplays_sidechain/bitcoin_transaction_tests.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/tests/tests/affiliate_tests.cpp b/tests/tests/affiliate_tests.cpp index 804d9e8a..c55c4440 100644 --- a/tests/tests/affiliate_tests.cpp +++ b/tests/tests/affiliate_tests.cpp @@ -524,17 +524,17 @@ BOOST_AUTO_TEST_CASE( bookie_payout_test ) CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); // place bets at 10:1 - place_bet(ath.paula_id, capitals_win_market.id, bet_type::back, asset(10000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(ath.penny_id, capitals_win_market.id, bet_type::lay, asset(100000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(ath.paula_id, capitals_win_market_id, bet_type::back, asset(10000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(ath.penny_id, capitals_win_market_id, bet_type::lay, asset(100000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION); // reverse positions at 1:1 - place_bet(ath.paula_id, capitals_win_market.id, bet_type::lay, asset(110000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(ath.penny_id, capitals_win_market.id, bet_type::back, asset(110000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(ath.paula_id, capitals_win_market_id, bet_type::lay, asset(110000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(ath.penny_id, capitals_win_market_id, bet_type::back, asset(110000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - update_betting_market_group(moneyline_betting_markets.id, graphene::chain::keywords::_status = betting_market_group_status::closed); - resolve_betting_market_group(moneyline_betting_markets.id, - {{capitals_win_market.id, betting_market_resolution_type::win}, - {blackhawks_win_market.id, betting_market_resolution_type::not_win}}); + update_betting_market_group(moneyline_betting_markets_id, graphene::chain::keywords::_status = betting_market_group_status::closed); + resolve_betting_market_group(moneyline_betting_markets_id, + {{capitals_win_market_id, betting_market_resolution_type::win}, + {blackhawks_win_market_id, betting_market_resolution_type::not_win}}); generate_block(); uint16_t rake_fee_percentage = db.get_global_properties().parameters.betting_rake_fee_percentage(); @@ -559,31 +559,31 @@ BOOST_AUTO_TEST_CASE( bookie_payout_test ) issue_uia( ath.paula_id, asset( 1000000, btc_id ) ); issue_uia( ath.petra_id, asset( 1000000, btc_id ) ); - create_event({{"en", "Washington Capitals/Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑鷹"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホークス"}}, {{"en", "2016-17"}}, nhl.id); \ + create_event({{"en", "Washington Capitals/Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑鷹"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホークス"}}, {{"en", "2016-17"}}, nhl_id); \ generate_blocks(1); \ - const event_object& capitals_vs_blackhawks2 = *db.get_index_type().indices().get().rbegin(); \ - create_betting_market_group({{"en", "Moneyline"}}, capitals_vs_blackhawks2.id, betting_market_rules.id, btc_id, false, 0); + const event_id_type capitals_vs_blackhawks2_id = (*db.get_index_type().indices().get().rbegin()).id; \ + create_betting_market_group({{"en", "Moneyline"}}, capitals_vs_blackhawks2_id, betting_market_rules_id, btc_id, false, 0); generate_blocks(1); - const betting_market_group_object& moneyline_betting_markets2 = *db.get_index_type().indices().get().rbegin(); - create_betting_market(moneyline_betting_markets2.id, {{"en", "Washington Capitals win"}}); + const betting_market_group_id_type moneyline_betting_markets2_id = (*db.get_index_type().indices().get().rbegin()).id; + create_betting_market(moneyline_betting_markets2_id, {{"en", "Washington Capitals win"}}); generate_blocks(1); - const betting_market_object& capitals_win_market2 = *db.get_index_type().indices().get().rbegin(); - create_betting_market(moneyline_betting_markets2.id, {{"en", "Chicago Blackhawks win"}}); + const betting_market_id_type capitals_win_market2_id = (*db.get_index_type().indices().get().rbegin()).id; + create_betting_market(moneyline_betting_markets2_id, {{"en", "Chicago Blackhawks win"}}); generate_blocks(1); - const betting_market_object& blackhawks_win_market2 = *db.get_index_type().indices().get().rbegin(); + const betting_market_id_type blackhawks_win_market2_id = (*db.get_index_type().indices().get().rbegin()).id; // place bets at 10:1 - place_bet(ath.paula_id, capitals_win_market2.id, bet_type::back, asset(10000, btc_id), 11 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(ath.petra_id, capitals_win_market2.id, bet_type::lay, asset(100000, btc_id), 11 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(ath.paula_id, capitals_win_market2_id, bet_type::back, asset(10000, btc_id), 11 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(ath.petra_id, capitals_win_market2_id, bet_type::lay, asset(100000, btc_id), 11 * GRAPHENE_BETTING_ODDS_PRECISION); // reverse positions at 1:1 - place_bet(ath.paula_id, capitals_win_market2.id, bet_type::lay, asset(110000, btc_id), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - place_bet(ath.petra_id, capitals_win_market2.id, bet_type::back, asset(110000, btc_id), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(ath.paula_id, capitals_win_market2_id, bet_type::lay, asset(110000, btc_id), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + place_bet(ath.petra_id, capitals_win_market2_id, bet_type::back, asset(110000, btc_id), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - update_betting_market_group(moneyline_betting_markets2.id, graphene::chain::keywords::_status = betting_market_group_status::closed); - resolve_betting_market_group(moneyline_betting_markets2.id, - {{capitals_win_market2.id, betting_market_resolution_type::not_win}, - {blackhawks_win_market2.id, betting_market_resolution_type::win}}); + update_betting_market_group(moneyline_betting_markets2_id, graphene::chain::keywords::_status = betting_market_group_status::closed); + resolve_betting_market_group(moneyline_betting_markets2_id, + {{capitals_win_market2_id, betting_market_resolution_type::not_win}, + {blackhawks_win_market2_id, betting_market_resolution_type::win}}); generate_block(); rake_value = (-10000 + 0 - 110000 + 220000) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100; diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 9885b548..7571feb6 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -51,7 +51,7 @@ genesis_state_type make_genesis() { auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); genesis_state.initial_active_witnesses = 10; - for( int i = 0; i < genesis_state.initial_active_witnesses; ++i ) + for( uint64_t i = 0; i < genesis_state.initial_active_witnesses; ++i ) { auto name = "init"+fc::to_string(i); genesis_state.initial_accounts.emplace_back(name, diff --git a/tests/tests/confidential_tests.cpp b/tests/tests/confidential_tests.cpp index a6a19f06..792a300e 100644 --- a/tests/tests/confidential_tests.cpp +++ b/tests/tests/confidential_tests.cpp @@ -64,7 +64,6 @@ BOOST_AUTO_TEST_CASE( confidential_test ) auto InB1 = fc::sha256::hash("InB1"); auto InB2 = fc::sha256::hash("InB2"); - auto OutB = fc::sha256::hash("InB2"); auto nonce1 = fc::sha256::hash("nonce"); auto nonce2 = fc::sha256::hash("nonce2"); diff --git a/tests/tests/database_tests.cpp b/tests/tests/database_tests.cpp index 9585d4a1..e0644b1b 100644 --- a/tests/tests/database_tests.cpp +++ b/tests/tests/database_tests.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE( merge_test ) try { database db; auto ses = db._undo_db.start_undo_session(); - const auto& bal_obj1 = db.create( [&]( account_balance_object& obj ){ + db.create( [&]( account_balance_object& obj ){ obj.balance = 42; }); ses.merge(); diff --git a/tests/tests/dividend_tests.cpp b/tests/tests/dividend_tests.cpp index a3869b36..facf77fb 100644 --- a/tests/tests/dividend_tests.cpp +++ b/tests/tests/dividend_tests.cpp @@ -219,8 +219,6 @@ BOOST_AUTO_TEST_CASE( test_basic_dividend_distribution ) const account_object& alice = get_account("alice"); const account_object& bob = get_account("bob"); const account_object& carol = get_account("carol"); - const account_object& dave = get_account("dave"); - const account_object& frank = get_account("frank"); const auto& test_asset_object = get_asset("TESTB"); auto issue_asset_to_account = [&](const asset_object& asset_to_issue, const account_object& destination_account, int64_t amount_to_issue) @@ -379,7 +377,6 @@ BOOST_AUTO_TEST_CASE( test_basic_dividend_distribution_to_core_asset ) const account_object& bob = get_account("bob"); const account_object& carol = get_account("carol"); const account_object& dave = get_account("dave"); - const account_object& frank = get_account("frank"); const auto& test_asset_object = get_asset("TESTB"); auto issue_asset_to_account = [&](const asset_object& asset_to_issue, const account_object& destination_account, int64_t amount_to_issue) @@ -513,28 +510,6 @@ BOOST_AUTO_TEST_CASE( test_basic_dividend_distribution_to_core_asset ) } } -BOOST_AUTO_TEST_CASE( test_dividend_distribution_interval ) -{ - using namespace graphene; - try { - INVOKE( create_dividend_uia ); - - const auto& dividend_holder_asset_object = get_asset("DIVIDEND"); - const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); - const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); - const account_object& alice = get_account("alice"); - const account_object& bob = get_account("bob"); - const account_object& carol = get_account("carol"); - const account_object& dave = get_account("dave"); - const account_object& frank = get_account("frank"); - const auto& test_asset_object = get_asset("TESTB"); - } catch(fc::exception& e) { - edump((e.to_detail_string())); - throw; - } -} - - BOOST_AUTO_TEST_CASE( check_dividend_corner_cases ) { using namespace graphene; @@ -547,8 +522,6 @@ BOOST_AUTO_TEST_CASE( check_dividend_corner_cases ) const account_object& alice = get_account("alice"); const account_object& bob = get_account("bob"); const account_object& carol = get_account("carol"); - const account_object& dave = get_account("dave"); - const account_object& frank = get_account("frank"); const auto& test_asset_object = get_asset("TESTB"); auto issue_asset_to_account = [&](const asset_object& asset_to_issue, const account_object& destination_account, int64_t amount_to_issue) @@ -570,16 +543,6 @@ BOOST_AUTO_TEST_CASE( check_dividend_corner_cases ) BOOST_CHECK_EQUAL(pending_balance, expected_balance); }; - auto reserve_asset_from_account = [&](const asset_object& asset_to_reserve, const account_object& from_account, int64_t amount_to_reserve) - { - asset_reserve_operation reserve_op; - reserve_op.payer = from_account.id; - reserve_op.amount_to_reserve = asset(amount_to_reserve, asset_to_reserve.id); - trx.operations.push_back(reserve_op); - set_expiration(db, trx); - PUSH_TX( db, trx, ~0 ); - trx.operations.clear(); - }; auto advance_to_next_payout_time = [&]() { // Advance to the next upcoming payout time BOOST_REQUIRE(dividend_data.options.next_payout_time); diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp index 14be6fe2..f716281e 100644 --- a/tests/tests/gpos_tests.cpp +++ b/tests/tests/gpos_tests.cpp @@ -79,7 +79,7 @@ struct gpos_fixture: database_fixture op.owner = owner; op.amount = amount; //op.balance_type = type; - + trx.operations.push_back(op); set_expiration(db, trx); trx.validate(); @@ -392,7 +392,7 @@ BOOST_AUTO_TEST_CASE( gpos_basic_dividend_distribution_to_core_asset ) PUSH_TX( db, trx, ~0 ); trx.operations.clear(); } - + // pass hardfork generate_blocks( HARDFORK_GPOS_TIME ); generate_block(); @@ -475,11 +475,11 @@ BOOST_AUTO_TEST_CASE( gpos_basic_dividend_distribution_to_core_asset ) vote_for(dave_id, witness1.vote_id, dave_private_key); // issuing 30000 TESTB to the dividend account - // alice and dave should receive 10000 TESTB as they have gpos vesting and + // alice and dave should receive 10000 TESTB as they have gpos vesting and // participated in voting // bob should not receive any TESTB as he doesn't have gpos vested // carol should not receive any TESTB as she doesn't participated in voting - // remaining 10000 TESTB should be deposited in commitee_accoount. + // remaining 10000 TESTB should be deposited in commitee_accoount. BOOST_TEST_MESSAGE("Issuing 30000 TESTB to the dividend account"); issue_asset_to_account(test_asset_object, dividend_distribution_account, 30000); @@ -531,7 +531,7 @@ BOOST_AUTO_TEST_CASE( gpos_basic_dividend_distribution_to_core_asset ) } catch(fc::exception& e) { edump((e.to_detail_string())); throw; - } + } } BOOST_AUTO_TEST_CASE( votes_on_gpos_activation ) @@ -546,7 +546,6 @@ BOOST_AUTO_TEST_CASE( votes_on_gpos_activation ) generate_block(); // update default gpos - auto now = db.head_block_time(); // 5184000 = 60x60x24x6 = 6 days // 864000 = 60x60x24x1 = 1 days update_gpos_global(518400, 86400, HARDFORK_GPOS_TIME); @@ -574,7 +573,7 @@ BOOST_AUTO_TEST_CASE( votes_on_gpos_activation ) witness2 = witness_id_type(2)(db); BOOST_CHECK_EQUAL(witness1.total_votes, 1000); BOOST_CHECK_EQUAL(witness2.total_votes, 1000); - + update_maintenance_interval(3600); //update maintenance interval to 1hr to evaluate sub-periods BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, 3600); @@ -671,10 +670,18 @@ BOOST_AUTO_TEST_CASE( voting ) auto witness2 = witness_id_type(2)(db); BOOST_CHECK_EQUAL(witness2.total_votes, 0); + // vesting performance is 0 for both alice and bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 0); + // vote for witness1 and witness2 - sub-period 1 vote_for(alice_id, witness1.vote_id, alice_private_key); vote_for(bob_id, witness2.vote_id, bob_private_key); + // after voting, vesting performance is 1 for both alice and bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + // go to maint generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); @@ -684,6 +691,10 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 1000); BOOST_CHECK_EQUAL(witness2.total_votes, 1000); + // vesting performance is 1 for both alice and bob during whole gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + advance_x_maint(6); witness1 = witness_id_type(1)(db); @@ -691,10 +702,29 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 100); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - advance_x_maint(4); + // vesting performance is 1 for both alice and bob during whole gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(3); + + // vesting performance is 1 for both alice and bob during whole gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(1); + + // new subperiod started, vesting performance is decreased to 5/6 for both alice and bob, until they vote + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0); //Bob votes for witness2 - sub-period 2 vote_for(bob_id, witness2.vote_id, bob_private_key); + + // after voting, vesting performance is 5/6 for alice and 1 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + // go to maint generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); // vote decay as time pass @@ -703,10 +733,36 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 83); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - - advance_x_maint(10); + + // after voting, vesting performance is 5/6 for alice and 1 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(4); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(4); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(1); + + // new subperiod started, vesting performance is decreased to 4/6 for alice and 5/6 for bob, until they vote + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0); + //Bob votes for witness2 - sub-period 3 vote_for(bob_id, witness2.vote_id, bob_private_key); + + // after voting, vesting performance is 4/6 for alice and 1 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); // decay more witness1 = witness_id_type(1)(db); @@ -714,8 +770,28 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 66); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - advance_x_maint(10); - + // after voting, vesting performance is 4/6 for alice and 1 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(4); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(4); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(1); + + // new subperiod started, vesting performance is decreased to 3/6 for alice and 5/6 for bob, until they vote + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 3.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0); + // Bob votes for witness2 - sub-period 4 vote_for(bob_id, witness2.vote_id, bob_private_key); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); @@ -725,8 +801,28 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 50); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - advance_x_maint(10); - + // after voting, vesting performance is 3/6 for alice and 1 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 3.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(4); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 3.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(4); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 3.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(1); + + // new subperiod started, vesting performance is decreased to 2/6 for alice and 5/6 for bob, until they vote + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 2.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0); + // Bob votes for witness2 - sub-period 5 vote_for(bob_id, witness2.vote_id, bob_private_key); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); @@ -737,8 +833,28 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 33); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - advance_x_maint(10); - + // after voting, vesting performance is 2/6 for alice and 1 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 2.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(4); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 2.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(4); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 2.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(1); + + // new subperiod started, vesting performance is decreased to 1/6 for alice and 5/6 for bob, until they vote + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0); + // Bob votes for witness2 - sub-period 6 vote_for(bob_id, witness2.vote_id, bob_private_key); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); @@ -748,14 +864,31 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 16); BOOST_CHECK_EQUAL(witness2.total_votes, 100); + // after voting, vesting performance is 1/6 for alice and 1 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + // we are still in gpos period 1 BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch()); - advance_x_maint(5); + advance_x_maint(8); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(1); + // a new GPOS period is in but vote from user is before the start. Whoever votes in 6th sub-period, votes will carry now = db.head_block_time(); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), HARDFORK_GPOS_TIME.sec_since_epoch() + db.get_global_properties().parameters.gpos_period()); + // new gpos period and his first subperiod started, + // vesting performance is decreased to 0 for alice, as she did not vote + // but stays 1 for bob, as he voted in last subperiod in previous gpos period + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1 ); + generate_block(); // we are in the second GPOS period, at subperiod 1, @@ -763,14 +896,16 @@ BOOST_AUTO_TEST_CASE( voting ) witness2 = witness_id_type(2)(db); BOOST_CHECK_EQUAL(witness1.total_votes, 0); //It's critical here, since bob votes in 6th sub-period of last vesting period, witness2 should retain his votes - BOOST_CHECK_EQUAL(witness2.total_votes, 100); - + BOOST_CHECK_EQUAL(witness2.total_votes, 100); // lets vote here from alice to generate votes for witness 1 //vote from bob to reatin VF 1 vote_for(alice_id, witness1.vote_id, alice_private_key); vote_for(bob_id, witness2.vote_id, bob_private_key); - generate_block(); + + // after voting, vesting performance is 1 for both alice and bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); // go to maint generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); @@ -781,7 +916,17 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 100); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - advance_x_maint(10); + advance_x_maint(8); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(1); + + // new subperiod started, vesting performance is decreased to 5/6 for both alice and bob, until they vote + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0); witness1 = witness_id_type(1)(db); witness2 = witness_id_type(2)(db); @@ -792,7 +937,21 @@ BOOST_AUTO_TEST_CASE( voting ) vote_for(bob_id, witness2.vote_id, bob_private_key); generate_block(); - advance_x_maint(10); + // after voting, vesting performance is 5/6 for alice and 1 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(9); + + // vesting performance does not change during gpos subperiod + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1); + + advance_x_maint(1); + + // new subperiod started, vesting performance is decreased to 4/6 for alice and 5/6 for bob, until they vote + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0); witness1 = witness_id_type(1)(db); witness2 = witness_id_type(2)(db); @@ -802,6 +961,11 @@ BOOST_AUTO_TEST_CASE( voting ) // alice votes again, now for witness 2, her vote worth 100 now vote_for(alice_id, witness2.vote_id, alice_private_key); + + // after voting, vesting performance is 1 for alice and 5.0/6.0 for bob + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1); + BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0); + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); witness1 = witness_id_type(1)(db); @@ -828,7 +992,7 @@ BOOST_AUTO_TEST_CASE( rolling_period_start ) BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, 3600); auto vesting_period_1 = db.get_global_properties().parameters.gpos_period_start(); - + auto now = db.head_block_time(); // moving outside period: while( db.head_block_time() <= now + fc::days(6) ) @@ -837,9 +1001,9 @@ BOOST_AUTO_TEST_CASE( rolling_period_start ) } generate_block(); auto vesting_period_2 = db.get_global_properties().parameters.gpos_period_start(); - - //difference between start of two consecutive vesting periods should be 6 days - BOOST_CHECK_EQUAL(vesting_period_1 + 518400, vesting_period_2); + + //difference between start of two consecutive vesting periods should be 6 days + BOOST_CHECK_EQUAL(vesting_period_1 + 518400, vesting_period_2); } catch (fc::exception &e) { edump((e.to_detail_string())); @@ -1067,7 +1231,7 @@ BOOST_AUTO_TEST_CASE( Withdraw_gpos_vesting_balance ) vbo1 = create_vesting(alice_id, core.amount(150), vesting_balance_type::gpos); vbo2 = create_vesting(bob_id, core.amount(99), vesting_balance_type::gpos); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - + generate_block(); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); @@ -1080,12 +1244,12 @@ BOOST_AUTO_TEST_CASE( Withdraw_gpos_vesting_balance ) BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 400); BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 99); - // Add more 50 and 73 vesting objects and withdraw 90 from + // Add more 50 and 73 vesting objects and withdraw 90 from // total vesting balance of user vbo1 = create_vesting(alice_id, core.amount(50), vesting_balance_type::gpos); vbo2 = create_vesting(alice_id, core.amount(73), vesting_balance_type::gpos); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - + generate_block(); vector vbos = db_api1.get_vesting_balances("alice"); @@ -1303,13 +1467,13 @@ BOOST_AUTO_TEST_CASE( proxy_voting ) // vote for witness1 auto witness1 = witness_id_type(1)(db); vote_for(bob_id, witness1.vote_id, bob_private_key); - + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - + // check vesting factor of current subperiod BOOST_CHECK_EQUAL(db_api.get_gpos_info(alice_id).vesting_factor, 1); BOOST_CHECK_EQUAL(db_api.get_gpos_info(bob_id).vesting_factor, 1); - + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); @@ -1317,7 +1481,7 @@ BOOST_AUTO_TEST_CASE( proxy_voting ) // vesting factor decay BOOST_CHECK_EQUAL(db_api.get_gpos_info(alice_id).vesting_factor, 0.83333333333333337); BOOST_CHECK_EQUAL(db_api.get_gpos_info(bob_id).vesting_factor, 0.83333333333333337); - + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); diff --git a/tests/tests/history_api_tests.cpp b/tests/tests/history_api_tests.cpp index f3b46fe7..8c975649 100644 --- a/tests/tests/history_api_tests.cpp +++ b/tests/tests/history_api_tests.cpp @@ -415,6 +415,8 @@ BOOST_AUTO_TEST_CASE(track_account) { // account_id_type() creates alice(not tracked account) const account_object& alice = create_account("alice"); auto alice_id = alice.id; + (void)alice; + (void)alice_id; //account_id_type() creates some ops create_bitasset("CNY", account_id_type()); @@ -423,6 +425,8 @@ BOOST_AUTO_TEST_CASE(track_account) { // account_id_type() creates dan(account tracked) const account_object& dan = create_account("dan"); auto dan_id = dan.id; + (void)dan; + (void)dan_id; // dan makes 1 op create_bitasset("EUR", dan_id); @@ -492,6 +496,8 @@ BOOST_AUTO_TEST_CASE(track_account2) { // account_id_type() creates alice(tracked account) const account_object& alice = create_account("alice"); auto alice_id = alice.id; + (void)alice; + (void)alice_id; //account_id_type() creates some ops create_bitasset("CNY", account_id_type()); @@ -503,6 +509,8 @@ BOOST_AUTO_TEST_CASE(track_account2) { // account_id_type() creates dan(account not tracked) const account_object& dan = create_account("dan"); auto dan_id = dan.id; + (void)dan; + (void)dan_id; generate_block(); diff --git a/tests/tests/lottery_tests.cpp b/tests/tests/lottery_tests.cpp index 063c15c1..c96abc09 100644 --- a/tests/tests/lottery_tests.cpp +++ b/tests/tests/lottery_tests.cpp @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE( lottery_idx_test ) while( test_itr != test_asset_idx.end() ) { if( !met_not_active && (!test_itr->is_lottery() || !test_itr->lottery_options->is_active) ) met_not_active = true; - FC_ASSERT( !met_not_active || met_not_active && (!test_itr->is_lottery() || !test_itr->lottery_options->is_active), "MET ACTIVE LOTTERY AFTER NOT ACTIVE" ); + FC_ASSERT( (!met_not_active) || (met_not_active && (!test_itr->is_lottery() || !test_itr->lottery_options->is_active)), "MET ACTIVE LOTTERY AFTER NOT ACTIVE" ); ++test_itr; } } catch (fc::exception& e) { @@ -128,7 +128,8 @@ BOOST_AUTO_TEST_CASE( tickets_purchase_test ) trx.operations.clear(); BOOST_CHECK( tpo.amount == db.get_balance( test_asset.get_id() ) ); - BOOST_CHECK( tpo.tickets_to_buy == get_balance( account_id_type(), test_asset.id ) ); + int64_t tickets_to_buy_int64 = tpo.tickets_to_buy; + BOOST_CHECK( tickets_to_buy_int64 == get_balance( account_id_type(), test_asset.id ) ); } catch (fc::exception& e) { edump((e.to_detail_string())); diff --git a/tests/tests/nft_lottery_tests.cpp b/tests/tests/nft_lottery_tests.cpp new file mode 100644 index 00000000..78e2ebf8 --- /dev/null +++ b/tests/tests/nft_lottery_tests.cpp @@ -0,0 +1,842 @@ +/* + * Copyright (c) 2017 PBSA, 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 "../common/database_fixture.hpp" + +#include +#include + +using namespace graphene::chain; +using namespace graphene::chain::test; + +BOOST_FIXTURE_TEST_SUITE(nft_lottery_tests, database_fixture) + +BOOST_AUTO_TEST_CASE(create_lottery_nft_md_test) +{ + try + { + generate_blocks(HARDFORK_NFT_TIME); + generate_block(); + generate_block(); + set_expiration(db, trx); + // Lottery Options + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + nft_lottery_options lottery_options; + lottery_options.benefactors.push_back(nft_lottery_benefactor(account_id_type(), 25 * GRAPHENE_1_PERCENT)); + lottery_options.end_date = db.head_block_time() + fc::minutes(5); + lottery_options.ticket_price = asset(100); + lottery_options.winning_tickets = {5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT}; + //lottery_options.winning_tickets = { 75 * GRAPHENE_1_PERCENT }; + lottery_options.is_active = test_nft_md_id.instance.value % 2 ? false : true; + lottery_options.ending_on_soldout = true; + + { + BOOST_TEST_MESSAGE("Send nft_metadata_create_operation"); + nft_metadata_create_operation op; + op.owner = account_id_type(); + op.symbol = "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value); + op.base_uri = "http://nft.example.com"; + op.is_transferable = true; + op.name = "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value); + op.max_supply = 200; + op.lottery_options = lottery_options; + + trx.operations.push_back(std::move(op)); + PUSH_TX(db, trx, ~0); + } + generate_block(); + + BOOST_TEST_MESSAGE("Check nft_metadata_create_operation results"); + + const auto &obj = test_nft_md_id(db); + BOOST_CHECK(obj.owner == account_id_type()); + BOOST_CHECK(obj.name == "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value)); + BOOST_CHECK(obj.symbol == "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value)); + BOOST_CHECK(obj.base_uri == "http://nft.example.com"); + BOOST_CHECK(obj.max_supply == share_type(200)); + BOOST_CHECK(obj.is_lottery()); + BOOST_CHECK(obj.get_token_current_supply(db) == share_type(0)); + BOOST_CHECK(obj.get_lottery_jackpot(db) == asset()); + BOOST_CHECK(obj.lottery_data->lottery_balance_id(db).sweeps_tickets_sold == share_type(0)); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(lottery_idx_test) +{ + try + { + // generate loterries with different end_dates and is_active_flag + for (int i = 0; i < 26; ++i) + { + generate_blocks(30); + graphene::chain::test::set_expiration(db, trx); + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto test_nft_md_obj = test_nft_md_id(db); + } + + auto &test_nft_md_idx = db.get_index_type().indices().get(); + auto test_itr = test_nft_md_idx.begin(); + bool met_not_active = false; + // check sorting + while (test_itr != test_nft_md_idx.end()) + { + if (!met_not_active && (!test_itr->is_lottery() || !test_itr->lottery_data->lottery_options.is_active)) + met_not_active = true; + FC_ASSERT(!met_not_active || met_not_active && (!test_itr->is_lottery() || !test_itr->lottery_data->lottery_options.is_active), "MET ACTIVE LOTTERY AFTER NOT ACTIVE"); + ++test_itr; + } + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(tickets_purchase_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + nft_id_type test_nft_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto &test_nft_md_obj = test_nft_md_id(db); + + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = account_id_type(); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 1; + tpo.amount = asset(100); + trx.operations.push_back(std::move(tpo)); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + generate_block(); + trx.operations.clear(); + auto &test_nft_ticket = test_nft_id(db); + BOOST_CHECK(test_nft_md_obj.get_token_current_supply(db) == tpo.tickets_to_buy); + BOOST_CHECK(test_nft_ticket.owner == tpo.buyer); + BOOST_CHECK(test_nft_ticket.nft_metadata_id == test_nft_md_obj.id); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(tickets_purchase_fail_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto &test_nft_md_obj = test_nft_md_id(db); + + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = account_id_type(); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 2; + tpo.amount = asset(100); + trx.operations.push_back(tpo); + BOOST_REQUIRE_THROW(PUSH_TX(db, trx, ~0), fc::exception); // amount/tickets_to_buy != price + trx.operations.clear(); + + tpo.amount = asset(205); + trx.operations.push_back(tpo); + BOOST_REQUIRE_THROW(PUSH_TX(db, trx, ~0), fc::exception); // amount/tickets_to_buy != price + + tpo.amount = asset(200, asset_id_type(1)); + trx.operations.push_back(tpo); + BOOST_REQUIRE_THROW(PUSH_TX(db, trx, ~0), fc::exception); // trying to buy in other asset + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(lottery_end_by_stage_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto test_nft_md_obj = test_nft_md_id(db); + for (int i = 1; i < 17; ++i) + { + if (i == 4 || i == 1 || i == 16 || i == 15) + continue; + if (i != 0) + transfer(account_id_type(), account_id_type(i), asset(100000)); + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = account_id_type(i); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = i; + tpo.amount = asset(100 * (i)); + trx.operations.push_back(std::move(tpo)); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + generate_block(); + trx.operations.clear(); + } + + test_nft_md_obj = test_nft_md_id(db); + uint64_t benefactor_balance_before_end = db.get_balance(account_id_type(), asset_id_type()).amount.value; + uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot(db).amount.value; + uint16_t winners_part = 0; + for (uint16_t win : test_nft_md_obj.lottery_data->lottery_options.winning_tickets) + winners_part += win; + + uint16_t participants_percents_sum = 0; + auto participants = test_nft_md_obj.distribute_winners_part(db); + for (auto p : participants) + { + for (auto e : p.second) + { + participants_percents_sum += e; + } + } + + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(participants_percents_sum == winners_part); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == (jackpot * (GRAPHENE_100_PERCENT - winners_part) / (double)GRAPHENE_100_PERCENT) + jackpot * winners_part * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT / (double)GRAPHENE_100_PERCENT); + test_nft_md_obj.distribute_benefactors_part(db); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == jackpot * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT * winners_part / (double)GRAPHENE_100_PERCENT); + test_nft_md_obj.distribute_sweeps_holders_part(db); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == 0); + + uint64_t benefactor_recieved = db.get_balance(account_id_type(), asset_id_type()).amount.value - benefactor_balance_before_end; + BOOST_CHECK(jackpot * test_nft_md_obj.lottery_data->lottery_options.benefactors[0].share / GRAPHENE_100_PERCENT == benefactor_recieved); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(lottery_end_by_stage_with_fractional_test) +{ + + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + db.modify(test_nft_md_id(db), [&](nft_metadata_object &obj) { + obj.lottery_data->lottery_options.is_active = true; + }); + auto test_nft_md_obj = test_nft_md_id(db); + + for (int i = 1; i < 17; ++i) + { + if (i == 4) + continue; + if (i != 0) + transfer(account_id_type(), account_id_type(i), asset(100000)); + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = account_id_type(i); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = i; + tpo.amount = asset(100 * (i)); + trx.operations.push_back(std::move(tpo)); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + generate_block(); + trx.operations.clear(); + } + test_nft_md_obj = test_nft_md_id(db); + uint64_t benefactor_balance_before_end = db.get_balance(account_id_type(), asset_id_type()).amount.value; + uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot(db).amount.value; + uint16_t winners_part = 0; + for (uint16_t win : test_nft_md_obj.lottery_data->lottery_options.winning_tickets) + winners_part += win; + + uint16_t participants_percents_sum = 0; + auto participants = test_nft_md_obj.distribute_winners_part(db); + for (auto p : participants) + for (auto e : p.second) + participants_percents_sum += e; + + BOOST_CHECK(participants_percents_sum == winners_part); + // balance should be bigger than expected because of rouning during distribution + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value > (jackpot * (GRAPHENE_100_PERCENT - winners_part) / (double)GRAPHENE_100_PERCENT) + jackpot * winners_part * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT / (double)GRAPHENE_100_PERCENT); + test_nft_md_obj.distribute_benefactors_part(db); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value > jackpot * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT * winners_part / (double)GRAPHENE_100_PERCENT); + test_nft_md_obj.distribute_sweeps_holders_part(db); + test_nft_md_obj = test_nft_md_id(db); + // but at the end is always equals 0 + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == 0); + + uint64_t benefactor_recieved = db.get_balance(account_id_type(), asset_id_type()).amount.value - benefactor_balance_before_end; + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(jackpot * test_nft_md_obj.lottery_data->lottery_options.benefactors[0].share / GRAPHENE_100_PERCENT == benefactor_recieved); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(lottery_end_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto test_nft_md_obj = test_nft_md_id(db); + for (int i = 1; i < 17; ++i) + { + if (i == 4 || i == 1 || i == 16 || i == 15) + continue; + if (i != 0) + transfer(account_id_type(), account_id_type(i), asset(100000)); + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = account_id_type(i); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = i; + tpo.amount = asset(100 * (i)); + trx.operations.push_back(std::move(tpo)); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + uint64_t creator_balance_before_end = db.get_balance(account_id_type(), asset_id_type()).amount.value; + uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot(db).amount.value; + uint16_t winners_part = 0; + for (uint8_t win : test_nft_md_obj.lottery_data->lottery_options.winning_tickets) + winners_part += win; + + while (db.head_block_time() < (test_nft_md_obj.lottery_data->lottery_options.end_date + fc::seconds(30))) + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == 0); + uint64_t creator_recieved = db.get_balance(account_id_type(), asset_id_type()).amount.value - creator_balance_before_end; + BOOST_CHECK(jackpot * test_nft_md_obj.lottery_data->lottery_options.benefactors[0].share / GRAPHENE_100_PERCENT == creator_recieved); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(claim_sweeps_vesting_balance_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(lottery_end_test); + auto test_nft_md_obj = test_nft_md_id(db); + account_id_type benefactor = test_nft_md_obj.lottery_data->lottery_options.benefactors[0].id; + const auto &svbo_index = db.get_index_type().indices().get(); + auto benefactor_svbo = svbo_index.find(benefactor); + BOOST_CHECK(benefactor_svbo != svbo_index.end()); + + auto balance_before_claim = db.get_balance(benefactor, SWEEPS_DEFAULT_DISTRIBUTION_ASSET); + auto available_for_claim = benefactor_svbo->available_for_claim(); + sweeps_vesting_claim_operation claim; + claim.account = benefactor; + claim.amount_to_claim = available_for_claim; + trx.clear(); + graphene::chain::test::set_expiration(db, trx); + trx.operations.push_back(claim); + PUSH_TX(db, trx, ~0); + generate_block(); + + BOOST_CHECK(db.get_balance(benefactor, SWEEPS_DEFAULT_DISTRIBUTION_ASSET) - balance_before_claim == available_for_claim); + benefactor_svbo = svbo_index.find(benefactor); + BOOST_CHECK(benefactor_svbo->available_for_claim().amount == 0); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(more_winners_then_participants_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto test_nft_md_obj = test_nft_md_id(db); + for (int i = 1; i < 4; ++i) + { + if (i == 4) + continue; + if (i != 0) + transfer(account_id_type(), account_id_type(i), asset(1000000)); + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = account_id_type(i); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 1; + tpo.amount = asset(100); + trx.operations.push_back(std::move(tpo)); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + auto holders = test_nft_md_obj.get_holders(db); + auto participants = test_nft_md_obj.distribute_winners_part(db); + test_nft_md_obj = test_nft_md_id(db); + test_nft_md_obj.distribute_benefactors_part(db); + test_nft_md_obj = test_nft_md_id(db); + test_nft_md_obj.distribute_sweeps_holders_part(db); + test_nft_md_obj = test_nft_md_id(db); + generate_block(); + for (auto p : participants) + { + idump((get_operation_history(p.first))); + } + auto benefactor_history = get_operation_history(account_id_type()); + for (auto h : benefactor_history) + { + idump((h)); + } + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(ending_by_date_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto test_nft_md_obj = test_nft_md_id(db); + for (int i = 1; i < 4; ++i) + { + if (i == 4) + continue; + if (i != 0) + transfer(account_id_type(), account_id_type(i), asset(1000000)); + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = account_id_type(i); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 1; + tpo.amount = asset(100); + trx.operations.push_back(std::move(tpo)); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + auto holders = test_nft_md_obj.get_holders(db); + idump((test_nft_md_obj.get_lottery_jackpot(db))); + while (db.head_block_time() < (test_nft_md_obj.lottery_data->lottery_options.end_date + fc::seconds(30))) + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + idump((test_nft_md_obj.get_lottery_jackpot(db))); + vector participants = {account_id_type(1), account_id_type(2), account_id_type(3)}; + for (auto p : participants) + { + idump((get_operation_history(p))); + } + auto benefactor_history = get_operation_history(account_id_type()); + for (auto h : benefactor_history) + { + if (h.op.which() == operation::tag::value) + { + auto reward_op = h.op.get(); + idump((reward_op)); + BOOST_CHECK(reward_op.is_benefactor_reward); + BOOST_CHECK(reward_op.amount.amount.value == 75); + BOOST_CHECK(reward_op.amount.asset_id == test_nft_md_obj.lottery_data->lottery_options.ticket_price.asset_id); + break; + } + } + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(ending_by_participants_count_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto test_nft_md_obj = test_nft_md_id(db); + FC_ASSERT(test_nft_md_obj.lottery_data->lottery_options.is_active); + account_id_type buyer(3); + transfer(account_id_type(), buyer, asset(10000000)); + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = buyer; + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 200; + tpo.amount = asset(200 * 100); + trx.operations.push_back(tpo); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + FC_ASSERT(!test_nft_md_obj.lottery_data->lottery_options.is_active); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(try_to_end_empty_lottery_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto test_nft_md_obj = test_nft_md_id(db); + while (db.head_block_time() < (test_nft_md_obj.lottery_data->lottery_options.end_date + fc::seconds(30))) + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(!test_nft_md_obj.lottery_data->lottery_options.is_active); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(lottery_winner_ticket_id_test) +{ + try + { + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + INVOKE(create_lottery_nft_md_test); + auto test_nft_md_obj = test_nft_md_id(db); + for (int i = 1; i < 4; ++i) + { + transfer(account_id_type(), account_id_type(i), asset(2000000)); + } + for (int i = 1; i < 4; ++i) + { + if (i == 4) + continue; + nft_lottery_token_purchase_operation tpo; + tpo.buyer = account_id_type(i); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 1; + tpo.amount = asset(100); + trx.operations.push_back(std::move(tpo)); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + + for (int i = 1; i < 4; ++i) + { + if (i == 4) + continue; + nft_lottery_token_purchase_operation tpo; + tpo.buyer = account_id_type(i); + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 1; + tpo.amount = asset(100); + trx.operations.push_back(std::move(tpo)); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + uint64_t creator_balance_before_end = db.get_balance(account_id_type(), asset_id_type()).amount.value; + uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot(db).amount.value; + uint16_t winners_part = 0; + for (uint8_t win : test_nft_md_obj.lottery_data->lottery_options.winning_tickets) + winners_part += win; + + while (db.head_block_time() < (test_nft_md_obj.lottery_data->lottery_options.end_date)) + generate_block(); + auto op_history = get_operation_history(account_id_type(1)); //Can observe operation 79 to verify winner ticket number + for (auto h : op_history) + { + idump((h)); + } + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == 0); + uint64_t creator_recieved = db.get_balance(account_id_type(), asset_id_type()).amount.value - creator_balance_before_end; + BOOST_CHECK(jackpot * test_nft_md_obj.lottery_data->lottery_options.benefactors[0].share / GRAPHENE_100_PERCENT == creator_recieved); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(create_lottery_nft_md_delete_tickets_on_draw_test) +{ + try + { + generate_blocks(HARDFORK_NFT_TIME); + generate_block(); + generate_block(); + set_expiration(db, trx); + // Lottery Options + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + nft_lottery_options lottery_options; + lottery_options.benefactors.push_back(nft_lottery_benefactor(account_id_type(), 25 * GRAPHENE_1_PERCENT)); + lottery_options.end_date = db.head_block_time() + fc::minutes(5); + lottery_options.ticket_price = asset(100); + lottery_options.winning_tickets = {5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT}; + //lottery_options.winning_tickets = { 75 * GRAPHENE_1_PERCENT }; + lottery_options.is_active = test_nft_md_id.instance.value % 2 ? false : true; + lottery_options.ending_on_soldout = true; + lottery_options.delete_tickets_after_draw = true; + + { + BOOST_TEST_MESSAGE("Send nft_metadata_create_operation"); + nft_metadata_create_operation op; + op.owner = account_id_type(); + op.symbol = "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value); + op.base_uri = "http://nft.example.com"; + op.is_transferable = true; + op.name = "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value); + op.max_supply = 200; + op.lottery_options = lottery_options; + + trx.operations.push_back(std::move(op)); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + + BOOST_TEST_MESSAGE("Check nft_metadata_create_operation results"); + + auto test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.owner == account_id_type()); + BOOST_CHECK(test_nft_md_obj.name == "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value)); + BOOST_CHECK(test_nft_md_obj.symbol == "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value)); + BOOST_CHECK(test_nft_md_obj.base_uri == "http://nft.example.com"); + BOOST_CHECK(test_nft_md_obj.max_supply == share_type(200)); + BOOST_CHECK(test_nft_md_obj.is_lottery()); + BOOST_CHECK(test_nft_md_obj.get_token_current_supply(db) == share_type(0)); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db) == asset()); + BOOST_CHECK(test_nft_md_obj.lottery_data->lottery_balance_id(db).sweeps_tickets_sold == share_type(0)); + + BOOST_CHECK(test_nft_md_obj.lottery_data->lottery_options.is_active); + account_id_type buyer(3); + transfer(account_id_type(), buyer, asset(10000000)); + { + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = buyer; + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 199; + tpo.amount = asset(199 * 100); + trx.operations.push_back(tpo); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.lottery_data->lottery_options.is_active); + BOOST_CHECK(test_nft_md_obj.get_token_current_supply(db) == 199); + { + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = buyer; + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 1; + tpo.amount = asset(1 * 100); + trx.operations.push_back(tpo); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(!test_nft_md_obj.lottery_data->lottery_options.is_active); + BOOST_CHECK(test_nft_md_obj.get_token_current_supply(db) == 0); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE(create_lottery_nft_with_permission_test) +{ + try + { + generate_blocks(HARDFORK_NFT_TIME); + generate_block(); + generate_block(); + set_expiration(db, trx); + // Lottery Options + nft_metadata_id_type test_nft_md_id = db.get_index().get_next_id(); + nft_lottery_options lottery_options; + lottery_options.benefactors.push_back(nft_lottery_benefactor(account_id_type(), 25 * GRAPHENE_1_PERCENT)); + lottery_options.end_date = db.head_block_time() + fc::minutes(5); + lottery_options.ticket_price = asset(100); + lottery_options.winning_tickets = {5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT}; + //lottery_options.winning_tickets = { 75 * GRAPHENE_1_PERCENT }; + lottery_options.is_active = test_nft_md_id.instance.value % 2 ? false : true; + lottery_options.ending_on_soldout = true; + lottery_options.delete_tickets_after_draw = true; + + account_id_type buyer1(3); + account_id_type buyer2(6); + generate_block(); + transfer(account_id_type(), buyer1, asset(1000000)); + transfer(account_id_type(), buyer2, asset(1000000)); + generate_block(); + + { + BOOST_TEST_MESSAGE("Send account_role_create_operation"); + + account_role_create_operation op; + op.owner = account_id_type(); + op.name = "Test Account Role"; + op.metadata = "{\"country\": \"earth\", \"race\": \"human\" }"; + + int ops[] = {operation::tag::value}; + op.allowed_operations.insert(ops, ops + 1); + op.whitelisted_accounts.emplace(buyer1); + op.valid_to = db.head_block_time() + 1000; + + trx.operations.push_back(op); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + + { + BOOST_TEST_MESSAGE("Send nft_metadata_create_operation"); + nft_metadata_create_operation op; + op.owner = account_id_type(); + op.symbol = "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value); + op.base_uri = "http://nft.example.com"; + op.is_transferable = true; + op.name = "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value); + op.max_supply = 200; + op.lottery_options = lottery_options; + op.account_role = account_role_id_type(0); + + trx.operations.push_back(std::move(op)); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + + BOOST_TEST_MESSAGE("Check nft_metadata_create_operation results"); + + auto test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.owner == account_id_type()); + BOOST_CHECK(test_nft_md_obj.name == "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value)); + BOOST_CHECK(test_nft_md_obj.symbol == "NFTLOTTERY" + std::to_string(test_nft_md_id.instance.value)); + BOOST_CHECK(test_nft_md_obj.base_uri == "http://nft.example.com"); + BOOST_CHECK(test_nft_md_obj.max_supply == share_type(200)); + BOOST_CHECK(test_nft_md_obj.is_lottery()); + BOOST_CHECK(test_nft_md_obj.get_token_current_supply(db) == share_type(0)); + BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db) == asset()); + BOOST_CHECK(test_nft_md_obj.lottery_data->lottery_balance_id(db).sweeps_tickets_sold == share_type(0)); + BOOST_CHECK(test_nft_md_obj.account_role == account_role_id_type(0)); + + BOOST_CHECK(test_nft_md_obj.lottery_data->lottery_options.is_active); + + { + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = buyer1; + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 199; + tpo.amount = asset(199 * 100); + trx.operations.push_back(tpo); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.lottery_data->lottery_options.is_active); + BOOST_CHECK(test_nft_md_obj.get_token_current_supply(db) == 199); + { + nft_lottery_token_purchase_operation tpo; + tpo.fee = asset(); + tpo.buyer = buyer2; + tpo.lottery_id = test_nft_md_obj.id; + tpo.tickets_to_buy = 1; + tpo.amount = asset(1 * 100); + trx.operations.push_back(tpo); + set_expiration(db, trx); + BOOST_CHECK_THROW(PUSH_TX(db, trx, ~0), fc::exception); + trx.operations.clear(); + } + generate_block(); + test_nft_md_obj = test_nft_md_id(db); + BOOST_CHECK(test_nft_md_obj.get_token_current_supply(db) == 199); + } + catch (fc::exception &e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 3093f0b0..6caec826 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -1561,7 +1561,6 @@ BOOST_AUTO_TEST_CASE( vesting_balance_create_test ) op.amount = test_asset.amount( 100 ); //op.vesting_seconds = 60*60*24; op.policy = cdd_vesting_policy_initializer{ 60*60*24 }; - op.balance_type == vesting_balance_type::normal; // Fee must be non-negative REQUIRE_OP_VALIDATION_SUCCESS( op, fee, core.amount(1) ); diff --git a/tests/tests/voting_tests.cpp b/tests/tests/voting_tests.cpp index 79f80e1f..a6f41675 100644 --- a/tests/tests/voting_tests.cpp +++ b/tests/tests/voting_tests.cpp @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(last_voting_date_proxy) PUSH_TX( db, trx, ~0 ); } // last_vote_time is not updated - auto round2 = db.head_block_time().sec_since_epoch(); + db.head_block_time().sec_since_epoch(); alice_stats_obj = alice_id(db).statistics(db); BOOST_CHECK_EQUAL(alice_stats_obj.last_vote_time.sec_since_epoch(), round1); diff --git a/tests/tournament/tournament_tests.cpp b/tests/tournament/tournament_tests.cpp index 8aa88479..0593fd79 100644 --- a/tests/tournament/tournament_tests.cpp +++ b/tests/tournament/tournament_tests.cpp @@ -1731,7 +1731,8 @@ BOOST_FIXTURE_TEST_CASE( ties, database_fixture ) share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); 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; players_balances[winner_id][tournament.options.buy_in.asset_id] += tournament.prize_pool - rake_amount; + players_balances[*dividend_account][tournament.options.buy_in.asset_id] += rake_amount; + players_balances[winner_id][tournament.options.buy_in.asset_id] += tournament.prize_pool - rake_amount; tournaments.erase(tournament_id); --tournaments_to_complete; @@ -1943,7 +1944,8 @@ BOOST_FIXTURE_TEST_CASE( assets, database_fixture ) share_type rake_amount = (fc::uint128_t(tournament.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); 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; players_balances[winner_id][tournament.options.buy_in.asset_id] += tournament.prize_pool - rake_amount; + players_balances[*dividend_account][tournament.options.buy_in.asset_id] += rake_amount; + players_balances[winner_id][tournament.options.buy_in.asset_id] += tournament.prize_pool - rake_amount; tournaments.erase(tournament_id); --tournaments_to_complete;