From 9955b390ee8af00fbc781e9f90aadfc8eb1a447a Mon Sep 17 00:00:00 2001 From: serkixenos Date: Wed, 1 Dec 2021 07:54:19 +0000 Subject: [PATCH 1/2] Merge Beatrice to Master 2021-11 --- .gitignore | 1 + CMakeLists.txt | 74 +- README.md | 1 - bkup_CMakeCache.txt | 794 ------------ clang-format.sh | 4 + libraries/CMakeLists.txt | 10 +- libraries/app/CMakeLists.txt | 30 +- libraries/app/api.cpp | 23 +- libraries/app/application.cpp | 1 - libraries/app/database_api.cpp | 90 +- libraries/app/include/graphene/app/api.hpp | 4 + libraries/chain/CMakeLists.txt | 142 +- libraries/chain/asset_evaluator.cpp | 1 - libraries/chain/asset_object.cpp | 2 +- libraries/chain/database.cpp | 2 +- libraries/chain/db_balance.cpp | 6 +- libraries/chain/db_bet.cpp | 4 - libraries/chain/db_block.cpp | 3 +- libraries/chain/db_getter.cpp | 34 +- libraries/chain/db_init.cpp | 21 +- libraries/chain/db_maint.cpp | 160 ++- libraries/chain/db_management.cpp | 27 +- libraries/chain/db_notify.cpp | 22 + libraries/chain/db_update.cpp | 9 +- libraries/chain/hardfork.d/NFT.hf | 4 +- libraries/chain/hardfork.d/SON.hf | 2 +- libraries/chain/hardfork.d/SON_FOR_HIVE.hf | 4 + .../graphene/chain/account_role_object.hpp | 2 +- .../chain/include/graphene/chain/database.hpp | 2 + .../global_betting_statistics_object.hpp | 2 +- .../chain/include/graphene/chain/impacted.hpp | 2 +- .../graphene/chain/nft_lottery_evaluator.hpp | 39 + .../include/graphene/chain/nft_object.hpp | 100 +- .../chain/protocol/chain_parameters.hpp | 10 + .../graphene/chain/protocol/nft_lottery.hpp | 86 ++ .../graphene/chain/protocol/nft_ops.hpp | 32 +- .../graphene/chain/protocol/operations.hpp | 8 +- .../graphene/chain/protocol/random_number.hpp | 25 + .../include/graphene/chain/protocol/types.hpp | 13 +- .../chain/random_number_evaluator.hpp | 19 + .../graphene/chain/random_number_object.hpp | 41 + .../graphene/chain/rbac_hardfork_visitor.hpp | 3 + .../include/graphene/chain/sidechain_defs.hpp | 4 +- .../chain/sidechain_transaction_object.hpp | 6 +- .../include/graphene/chain/son_object.hpp | 9 +- .../graphene/chain/vesting_balance_object.hpp | 20 +- libraries/chain/index.cpp | 43 - libraries/chain/nft_evaluator.cpp | 41 + libraries/chain/nft_lottery_evaluator.cpp | 145 +++ libraries/chain/nft_lottery_object.cpp | 171 +++ libraries/chain/proposal_evaluator.cpp | 12 + libraries/chain/protocol/competitor.cpp | 35 - libraries/chain/protocol/memo.cpp | 4 +- libraries/chain/protocol/nft.cpp | 4 + libraries/chain/protocol/nft_lottery.cpp | 38 + libraries/chain/random_number_evaluator.cpp | 24 + .../chain/sidechain_address_evaluator.cpp | 8 +- .../chain/sidechain_transaction_evaluator.cpp | 11 +- libraries/chain/son_object.cpp | 13 + .../chain/son_wallet_deposit_evaluator.cpp | 16 +- .../chain/son_wallet_withdraw_evaluator.cpp | 16 +- libraries/chain/tournament_object.cpp | 5 +- libraries/chain/transaction_object.cpp | 95 -- .../db/include/graphene/db/undo_database.hpp | 12 +- libraries/db/undo_database.cpp | 12 + libraries/egenesis/CMakeLists.txt | 8 +- libraries/net/CMakeLists.txt | 8 +- libraries/net/node.cpp | 2 + libraries/plugins/CMakeLists.txt | 14 +- .../plugins/account_history/CMakeLists.txt | 2 +- .../plugins/accounts_list/CMakeLists.txt | 2 +- .../plugins/affiliate_stats/CMakeLists.txt | 2 +- libraries/plugins/bookie/CMakeLists.txt | 2 +- .../plugins/debug_witness/CMakeLists.txt | 2 +- libraries/plugins/delayed_node/CMakeLists.txt | 2 +- .../plugins/elasticsearch/CMakeLists.txt | 14 +- .../elasticsearch/elasticsearch_plugin.cpp | 109 +- .../elasticsearch/elasticsearch_plugin.hpp | 35 +- libraries/plugins/es_objects/CMakeLists.txt | 14 +- libraries/plugins/es_objects/es_objects.cpp | 416 +++++- .../plugins/generate_genesis/CMakeLists.txt | 2 +- .../CMakeLists.txt | 2 +- .../grouped_orders/grouped_orders_plugin.cpp | 303 ----- .../plugins/market_history/CMakeLists.txt | 2 +- .../peerplays_sidechain/CMakeLists.txt | 9 +- .../bitcoin/bitcoin_script.cpp | 1 + .../bitcoin/bitcoin_transaction.cpp | 1 + .../bitcoin/sign_bitcoin_transaction.cpp | 3 + .../peerplays_sidechain/common/rpc_client.cpp | 185 +++ .../peerplays_sidechain/common/utils.cpp | 8 + .../peerplays_sidechain/hive/asset.cpp | 69 + .../peerplays_sidechain/hive/operations.cpp | 101 ++ .../peerplays_sidechain/hive/transaction.cpp | 57 + .../peerplays_sidechain/hive/types.cpp | 73 ++ .../peerplays_sidechain/common/rpc_client.hpp | 39 + .../peerplays_sidechain/common/utils.hpp | 5 + .../peerplays_sidechain/hive/asset.hpp | 41 + .../peerplays_sidechain/hive/authority.hpp | 33 + .../hive/hive_operations.hpp | 123 ++ .../peerplays_sidechain/hive/operations.hpp | 69 + .../peerplays_sidechain/hive/transaction.hpp | 44 + .../peerplays_sidechain/hive/types.hpp | 72 ++ .../peerplays_sidechain_plugin.hpp | 1 + .../sidechain_net_handler.hpp | 7 +- .../sidechain_net_handler_bitcoin.hpp | 14 +- .../sidechain_net_handler_hive.hpp | 68 + .../sidechain_net_handler_peerplays.hpp | 5 +- .../sidechain_net_manager.hpp | 2 + .../peerplays_sidechain_plugin.cpp | 98 +- .../sidechain_net_handler.cpp | 150 ++- .../sidechain_net_handler_bitcoin.cpp | 122 +- .../sidechain_net_handler_hive.cpp | 971 ++++++++++++++ .../sidechain_net_handler_peerplays.cpp | 107 +- .../sidechain_net_manager.cpp | 14 + libraries/plugins/snapshot/CMakeLists.txt | 2 +- libraries/plugins/witness/CMakeLists.txt | 2 +- libraries/plugins/witness/witness.cpp | 6 +- libraries/wallet/CMakeLists.txt | 2 +- .../wallet/include/graphene/wallet/wallet.hpp | 255 ++-- libraries/wallet/wallet.cpp | 296 ++++- programs/CMakeLists.txt | 4 +- programs/build_helpers/CMakeLists.txt | 4 +- programs/cli_wallet/CMakeLists.txt | 2 +- programs/debug_node/CMakeLists.txt | 2 +- programs/delayed_node/CMakeLists.txt | 2 +- programs/genesis_util/CMakeLists.txt | 6 +- .../js_operation_serializer/CMakeLists.txt | 2 +- programs/size_checker/CMakeLists.txt | 2 +- programs/witness_node/CMakeLists.txt | 2 +- programs/witness_node/genesis.json | 2 +- tests/CMakeLists.txt | 47 +- tests/betting/betting_tests.cpp | 1138 +++++++---------- tests/cli/son.cpp | 17 +- tests/common/betting_test_markets.hpp | 141 +- tests/common/database_fixture.cpp | 43 +- tests/common/database_fixture.hpp | 4 +- tests/generate_empty_blocks/CMakeLists.txt | 2 +- .../bitcoin_transaction_tests.cpp | 1 + tests/tests/affiliate_tests.cpp | 48 +- tests/tests/block_tests.cpp | 2 +- tests/tests/confidential_tests.cpp | 1 - tests/tests/database_tests.cpp | 2 +- tests/tests/dividend_tests.cpp | 37 - tests/tests/gpos_tests.cpp | 230 +++- tests/tests/history_api_tests.cpp | 8 + tests/tests/lottery_tests.cpp | 5 +- tests/tests/nft_lottery_tests.cpp | 842 ++++++++++++ tests/tests/operation_tests.cpp | 1 - tests/tests/son_operations_tests.cpp | 44 +- tests/tests/voting_tests.cpp | 2 +- tests/tournament/tournament_tests.cpp | 6 +- 151 files changed, 6357 insertions(+), 2891 deletions(-) delete mode 100644 bkup_CMakeCache.txt create mode 100755 clang-format.sh create mode 100644 libraries/chain/hardfork.d/SON_FOR_HIVE.hf create mode 100644 libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp create mode 100644 libraries/chain/include/graphene/chain/protocol/random_number.hpp create mode 100644 libraries/chain/include/graphene/chain/random_number_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/random_number_object.hpp delete mode 100644 libraries/chain/index.cpp create mode 100644 libraries/chain/nft_lottery_evaluator.cpp create mode 100644 libraries/chain/nft_lottery_object.cpp delete mode 100644 libraries/chain/protocol/competitor.cpp create mode 100644 libraries/chain/protocol/nft_lottery.cpp create mode 100644 libraries/chain/random_number_evaluator.cpp delete mode 100644 libraries/chain/transaction_object.cpp delete mode 100644 libraries/plugins/grouped_orders/grouped_orders_plugin.cpp create mode 100644 libraries/plugins/peerplays_sidechain/common/rpc_client.cpp create mode 100644 libraries/plugins/peerplays_sidechain/common/utils.cpp create mode 100644 libraries/plugins/peerplays_sidechain/hive/asset.cpp create mode 100644 libraries/plugins/peerplays_sidechain/hive/operations.cpp create mode 100644 libraries/plugins/peerplays_sidechain/hive/transaction.cpp create mode 100644 libraries/plugins/peerplays_sidechain/hive/types.cpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/rpc_client.hpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/asset.hpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/authority.hpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/operations.hpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/transaction.hpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_hive.hpp create mode 100644 libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp create mode 100644 tests/tests/nft_lottery_tests.cpp diff --git a/.gitignore b/.gitignore index 39b23163..1a84b559 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ data CMakeDoxyfile.in build +build__* libraries/utilities/git_revision.cpp 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/README.md b/README.md index 7173bcb1..e1ad6ef0 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,6 @@ make -j$(nproc) make install # this can install the executable files under /usr/local ``` -docker build -t peerplays . ## Docker image diff --git a/bkup_CMakeCache.txt b/bkup_CMakeCache.txt deleted file mode 100644 index daa267e9..00000000 --- a/bkup_CMakeCache.txt +++ /dev/null @@ -1,794 +0,0 @@ -# This is the CMakeCache file. -# For build in directory: /home/pbattu/git/18.04/peerplays -# It was generated by CMake: /usr/bin/cmake -# You can edit this file to change values found and used by cmake. -# If you do not want to change any of the values, simply exit the editor. -# If you do want to change a value, simply edit, save, and exit the editor. -# The syntax for the file is as follows: -# KEY:TYPE=VALUE -# KEY is the name of a variable in the cache. -# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. -# VALUE is the current value for the KEY. - -######################## -# EXTERNAL cache entries -######################## - -//No help, variable specified on the command line. -BOOST_ROOT:PATH=/home/pbattu/git/18.04/boost_1_67_0 - -//The threading library used by boost-thread -BOOST_THREAD_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpthread.so - -//Build bitshares executables (witness node, cli wallet, etc) -BUILD_BITSHARES_PROGRAMS:BOOL=TRUE - -//Build bitshares unit tests -BUILD_BITSHARES_TESTS:BOOL=TRUE - -//Build websocketpp examples. -BUILD_EXAMPLES:BOOL=OFF - -//Build websocketpp tests. -BUILD_TESTS:BOOL=OFF - -//Value Computed by CMake -BitShares_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays - -//Value Computed by CMake -BitShares_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays - -//Boost chrono library (debug) -Boost_CHRONO_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a - -//Boost chrono library (release) -Boost_CHRONO_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a - -//Boost context library (debug) -Boost_CONTEXT_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a - -//Boost context library (release) -Boost_CONTEXT_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a - -//Boost coroutine library (debug) -Boost_COROUTINE_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a - -//Boost coroutine library (release) -Boost_COROUTINE_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a - -//Boost date_time library (debug) -Boost_DATE_TIME_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a - -//Boost date_time library (release) -Boost_DATE_TIME_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a - -//The directory containing a CMake configuration file for Boost. -Boost_DIR:PATH=Boost_DIR-NOTFOUND - -//Boost filesystem library (debug) -Boost_FILESYSTEM_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a - -//Boost filesystem library (release) -Boost_FILESYSTEM_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a - -//Path to a file. -Boost_INCLUDE_DIR:PATH=/home/pbattu/git/18.04/boost_1_67_0/include - -//Boost iostreams library (debug) -Boost_IOSTREAMS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a - -//Boost iostreams library (release) -Boost_IOSTREAMS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a - -//Boost library directory -Boost_LIBRARY_DIR:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib - -//Boost library directory DEBUG -Boost_LIBRARY_DIR_DEBUG:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib - -//Boost library directory RELEASE -Boost_LIBRARY_DIR_RELEASE:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib - -//Boost locale library (debug) -Boost_LOCALE_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a - -//Boost locale library (release) -Boost_LOCALE_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a - -//Boost program_options library (debug) -Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a - -//Boost program_options library (release) -Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a - -//Boost serialization library (debug) -Boost_SERIALIZATION_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a - -//Boost serialization library (release) -Boost_SERIALIZATION_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a - -//Boost signals library (debug) -Boost_SIGNALS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a - -//Boost signals library (release) -Boost_SIGNALS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a - -//Boost system library (debug) -Boost_SYSTEM_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a - -//Boost system library (release) -Boost_SYSTEM_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a - -//Boost thread library (debug) -Boost_THREAD_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a - -//Boost thread library (release) -Boost_THREAD_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a - -//Boost unit_test_framework library (debug) -Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a - -//Boost unit_test_framework library (release) -Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a - -//ON or OFF -Boost_USE_STATIC_LIBS:STRING=ON - -//Path to a program. -CMAKE_AR:FILEPATH=/usr/bin/ar - -//Choose the type of build, options are: None(CMAKE_CXX_FLAGS or -// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel. -CMAKE_BUILD_TYPE:STRING=Debug - -//Enable/Disable color output during build. -CMAKE_COLOR_MAKEFILE:BOOL=ON - -//Configurations -CMAKE_CONFIGURATION_TYPES:STRING=Release;RelWithDebInfo;Debug - -//CXX compiler -CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++-5 - -//A wrapper around 'ar' adding the appropriate '--plugin' option -// for the GCC compiler -CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-5 - -//A wrapper around 'ranlib' adding the appropriate '--plugin' option -// for the GCC compiler -CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-5 - -//Flags used by the compiler during all build types. -CMAKE_CXX_FLAGS:STRING= - -//Flags used by the compiler during debug builds. -CMAKE_CXX_FLAGS_DEBUG:STRING=-g - -//Flags used by the compiler during release builds for minimum -// size. -CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG - -//Flags used by the compiler during release builds. -CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG - -//Flags used by the compiler during release builds with debug info. -CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG - -//C compiler -CMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc-5 - -//A wrapper around 'ar' adding the appropriate '--plugin' option -// for the GCC compiler -CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-5 - -//A wrapper around 'ranlib' adding the appropriate '--plugin' option -// for the GCC compiler -CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-5 - -//Flags used by the compiler during all build types. -CMAKE_C_FLAGS:STRING= - -//Flags used by the compiler during debug builds. -CMAKE_C_FLAGS_DEBUG:STRING=-g - -//Flags used by the compiler during release builds for minimum -// size. -CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG - -//Flags used by the compiler during release builds. -CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG - -//Flags used by the compiler during release builds with debug info. -CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG - -//Flags used by the linker. -CMAKE_EXE_LINKER_FLAGS:STRING= - -//Flags used by the linker during debug builds. -CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= - -//Flags used by the linker during release minsize builds. -CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= - -//Flags used by the linker during release builds. -CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= - -//Flags used by the linker during Release with Debug Info builds. -CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= - -//Enable/Disable output of compile commands during generation. -CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF - -//Install path prefix, prepended onto install directories. -CMAKE_INSTALL_PREFIX:PATH=/usr/local - -//Path to a program. -CMAKE_LINKER:FILEPATH=/usr/bin/ld - -//Path to a program. -CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make - -//Flags used by the linker during the creation of modules. -CMAKE_MODULE_LINKER_FLAGS:STRING= - -//Flags used by the linker during debug builds. -CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= - -//Flags used by the linker during release minsize builds. -CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= - -//Flags used by the linker during release builds. -CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= - -//Flags used by the linker during Release with Debug Info builds. -CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= - -//Path to a program. -CMAKE_NM:FILEPATH=/usr/bin/nm - -//Path to a program. -CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy - -//Path to a program. -CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump - -//Value Computed by CMake -CMAKE_PROJECT_NAME:STATIC=BitShares - -//Path to a program. -CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib - -//Flags used by the linker during the creation of dll's. -CMAKE_SHARED_LINKER_FLAGS:STRING= - -//Flags used by the linker during debug builds. -CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= - -//Flags used by the linker during release minsize builds. -CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= - -//Flags used by the linker during release builds. -CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= - -//Flags used by the linker during Release with Debug Info builds. -CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= - -//If set, runtime paths are not added when installing shared libraries, -// but are added when building. -CMAKE_SKIP_INSTALL_RPATH:BOOL=NO - -//If set, runtime paths are not added when using shared libraries. -CMAKE_SKIP_RPATH:BOOL=NO - -//Flags used by the linker during the creation of static libraries. -CMAKE_STATIC_LINKER_FLAGS:STRING= - -//Flags used by the linker during debug builds. -CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= - -//Flags used by the linker during release minsize builds. -CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= - -//Flags used by the linker during release builds. -CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= - -//Flags used by the linker during Release with Debug Info builds. -CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= - -//Path to a program. -CMAKE_STRIP:FILEPATH=/usr/bin/strip - -//If this value is on, makefiles will be generated without the -// .SILENT directive, and all commands will be echoed to the console -// during the make. This is useful for debugging only. With Visual -// Studio IDE projects all commands are done without /nologo. -CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE - -//Path to a library. -CURSES_CURSES_LIBRARY:FILEPATH=CURSES_CURSES_LIBRARY-NOTFOUND - -//Path to a library. -CURSES_FORM_LIBRARY:FILEPATH=CURSES_FORM_LIBRARY-NOTFOUND - -//Path to a file. -CURSES_INCLUDE_PATH:PATH=CURSES_INCLUDE_PATH-NOTFOUND - -//Path to a library. -CURSES_NCURSES_LIBRARY:FILEPATH=CURSES_NCURSES_LIBRARY-NOTFOUND - -//Dot tool for use with Doxygen -DOXYGEN_DOT_EXECUTABLE:FILEPATH=DOXYGEN_DOT_EXECUTABLE-NOTFOUND - -//Doxygen documentation generation tool (http://www.doxygen.org) -DOXYGEN_EXECUTABLE:FILEPATH=DOXYGEN_EXECUTABLE-NOTFOUND - -//secp256k1 or openssl or mixed -ECC_IMPL:STRING=secp256k1 - -//Build BitShares for code coverage analysis -ENABLE_COVERAGE_TESTING:BOOL=FALSE - -//Build websocketpp with CPP11 features enabled. -ENABLE_CPP11:BOOL=ON - -//TRUE to try to use full zlib for compression, FALSE to use miniz.c -FC_USE_FULL_ZLIB:BOOL=FALSE - -//Git command line client -GIT_EXECUTABLE:FILEPATH=/usr/bin/git - -//location of the genesis.json to embed in the executable -GRAPHENE_EGENESIS_JSON:PATH=/home/pbattu/git/18.04/peerplays/genesis.json - -//The directory containing a CMake configuration file for Gperftools. -Gperftools_DIR:PATH=Gperftools_DIR-NOTFOUND - -//Installation directory for CMake files -INSTALL_CMAKE_DIR:PATH=lib/cmake/websocketpp - -//Installation directory for header files -INSTALL_INCLUDE_DIR:PATH=include - -//Log long API calls over websocket (ON OR OFF) -LOG_LONG_API:BOOL=ON - -//Max API execution time in ms -LOG_LONG_API_MAX_MS:STRING=1000 - -//API execution time in ms at which to warn -LOG_LONG_API_WARN_MS:STRING=750 - -//Path to a library. -OPENSSL_CRYPTO_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libcrypto.a - -//Path to a file. -OPENSSL_INCLUDE_DIR:PATH=/usr/include - -//Path to a library. -OPENSSL_SSL_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libssl.a - -//Path to a program. -PERL_EXECUTABLE:FILEPATH=/usr/bin/perl - -//pkg-config executable -PKG_CONFIG_EXECUTABLE:FILEPATH=/usr/bin/pkg-config - -//Path to a file. -READLINE_INCLUDE_DIR:PATH=/usr/include - -//Path to a library. -READLINE_LIBRARIES:FILEPATH=/usr/lib/x86_64-linux-gnu/libreadline.so - -//Path to a file. -Readline_INCLUDE_DIR:PATH=/usr/include - -//Path to a library. -Readline_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libreadline.so - -//Path to a file. -Readline_ROOT_DIR:PATH=/usr - -//OFF -UNITY_BUILD:BOOL=OFF - -//Path to a file. -ZLIB_INCLUDE_DIR:PATH=/usr/include - -//Path to a library. -ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND - -//Path to a library. -ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libz.so - -//Value Computed by CMake -fc_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc - -//Dependencies for the target -fc_LIB_DEPENDS:STATIC=general;-L/usr/local/lib;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a;general;/usr/lib/x86_64-linux-gnu/libpthread.so;general;/usr/lib/x86_64-linux-gnu/libssl.a;general;/usr/lib/x86_64-linux-gnu/libcrypto.a;general;/usr/lib/x86_64-linux-gnu/libz.so;general;dl;general;rt;general;/usr/lib/x86_64-linux-gnu/libreadline.so;general;secp256k1; - -//Value Computed by CMake -fc_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc - -//Dependencies for the target -graphene_account_history_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Dependencies for the target -graphene_accounts_list_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Dependencies for the target -graphene_affiliate_stats_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Dependencies for the target -graphene_app_LIB_DEPENDS:STATIC=general;graphene_market_history;general;graphene_account_history;general;graphene_accounts_list;general;graphene_affiliate_stats;general;graphene_chain;general;fc;general;graphene_db;general;graphene_net;general;graphene_time;general;graphene_utilities;general;graphene_debug_witness;general;graphene_bookie; - -//Dependencies for the target -graphene_bookie_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Dependencies for the target -graphene_chain_LIB_DEPENDS:STATIC=general;fc;general;graphene_db; - -//Dependencies for the target -graphene_db_LIB_DEPENDS:STATIC=general;fc; - -//Dependencies for the target -graphene_debug_witness_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Dependencies for the target -graphene_delayed_node_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Dependencies for the target -graphene_egenesis_brief_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; - -//Dependencies for the target -graphene_egenesis_full_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; - -//Dependencies for the target -graphene_egenesis_none_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; - -//Dependencies for the target -graphene_generate_genesis_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app;general;graphene_time; - -//Dependencies for the target -graphene_generate_uia_sharedrop_genesis_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app;general;graphene_time; - -//Dependencies for the target -graphene_market_history_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Dependencies for the target -graphene_net_LIB_DEPENDS:STATIC=general;fc;general;graphene_db; - -//Dependencies for the target -graphene_snapshot_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Dependencies for the target -graphene_time_LIB_DEPENDS:STATIC=general;fc; - -//Dependencies for the target -graphene_utilities_LIB_DEPENDS:STATIC=general;fc; - -//Dependencies for the target -graphene_wallet_LIB_DEPENDS:STATIC=general;graphene_app;general;graphene_net;general;graphene_chain;general;graphene_utilities;general;fc;general;dl; - -//Dependencies for the target -graphene_witness_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; - -//Value Computed by CMake -websocketpp_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc/vendor/websocketpp - -//Value Computed by CMake -websocketpp_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc/vendor/websocketpp - - -######################## -# INTERNAL cache entries -######################## - -//ADVANCED property for variable: BOOST_ROOT -BOOST_ROOT-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_CHRONO_LIBRARY_DEBUG -Boost_CHRONO_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_CHRONO_LIBRARY_RELEASE -Boost_CHRONO_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_CONTEXT_LIBRARY_DEBUG -Boost_CONTEXT_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_CONTEXT_LIBRARY_RELEASE -Boost_CONTEXT_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_COROUTINE_LIBRARY_DEBUG -Boost_COROUTINE_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_COROUTINE_LIBRARY_RELEASE -Boost_COROUTINE_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_DATE_TIME_LIBRARY_DEBUG -Boost_DATE_TIME_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_DATE_TIME_LIBRARY_RELEASE -Boost_DATE_TIME_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_DIR -Boost_DIR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_FILESYSTEM_LIBRARY_DEBUG -Boost_FILESYSTEM_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_FILESYSTEM_LIBRARY_RELEASE -Boost_FILESYSTEM_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_INCLUDE_DIR -Boost_INCLUDE_DIR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_IOSTREAMS_LIBRARY_DEBUG -Boost_IOSTREAMS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_IOSTREAMS_LIBRARY_RELEASE -Boost_IOSTREAMS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_LIBRARY_DIR -Boost_LIBRARY_DIR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_LIBRARY_DIR_DEBUG -Boost_LIBRARY_DIR_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_LIBRARY_DIR_RELEASE -Boost_LIBRARY_DIR_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_LOCALE_LIBRARY_DEBUG -Boost_LOCALE_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_LOCALE_LIBRARY_RELEASE -Boost_LOCALE_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG -Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE -Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_SERIALIZATION_LIBRARY_DEBUG -Boost_SERIALIZATION_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_SERIALIZATION_LIBRARY_RELEASE -Boost_SERIALIZATION_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_SIGNALS_LIBRARY_DEBUG -Boost_SIGNALS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_SIGNALS_LIBRARY_RELEASE -Boost_SIGNALS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_SYSTEM_LIBRARY_DEBUG -Boost_SYSTEM_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_SYSTEM_LIBRARY_RELEASE -Boost_SYSTEM_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_THREAD_LIBRARY_DEBUG -Boost_THREAD_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_THREAD_LIBRARY_RELEASE -Boost_THREAD_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG -Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE -Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_AR -CMAKE_AR-ADVANCED:INTERNAL=1 -//This is the directory where this CMakeCache.txt was created -CMAKE_CACHEFILE_DIR:INTERNAL=/home/pbattu/git/18.04/peerplays -//Major version of cmake used to create the current loaded cache -CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 -//Minor version of cmake used to create the current loaded cache -CMAKE_CACHE_MINOR_VERSION:INTERNAL=10 -//Patch version of cmake used to create the current loaded cache -CMAKE_CACHE_PATCH_VERSION:INTERNAL=2 -//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE -CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 -//Path to CMake executable. -CMAKE_COMMAND:INTERNAL=/usr/bin/cmake -//Path to cpack program executable. -CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack -//Path to ctest program executable. -CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest -//ADVANCED property for variable: CMAKE_CXX_COMPILER -CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR -CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB -CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_CXX_FLAGS -CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG -CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL -CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE -CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO -CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_C_COMPILER -CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_C_COMPILER_AR -CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB -CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_C_FLAGS -CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG -CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL -CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE -CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO -CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 -//Executable file format -CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF -//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS -CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG -CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL -CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE -CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO -CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS -CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 -//Name of external makefile project generator. -CMAKE_EXTRA_GENERATOR:INTERNAL= -//Name of generator. -CMAKE_GENERATOR:INTERNAL=Unix Makefiles -//Name of generator platform. -CMAKE_GENERATOR_PLATFORM:INTERNAL= -//Name of generator toolset. -CMAKE_GENERATOR_TOOLSET:INTERNAL= -//Have symbol pthread_create -CMAKE_HAVE_LIBC_CREATE:INTERNAL= -//Have library pthreads -CMAKE_HAVE_PTHREADS_CREATE:INTERNAL= -//Have library pthread -CMAKE_HAVE_PTHREAD_CREATE:INTERNAL=1 -//Have include pthread.h -CMAKE_HAVE_PTHREAD_H:INTERNAL=1 -//Source directory with the top level CMakeLists.txt file for this -// project -CMAKE_HOME_DIRECTORY:INTERNAL=/home/pbattu/git/18.04/peerplays -//Install .so files without execute permission. -CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1 -//ADVANCED property for variable: CMAKE_LINKER -CMAKE_LINKER-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_MAKE_PROGRAM -CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS -CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG -CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL -CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE -CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO -CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_NM -CMAKE_NM-ADVANCED:INTERNAL=1 -//number of local generators -CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=37 -//ADVANCED property for variable: CMAKE_OBJCOPY -CMAKE_OBJCOPY-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_OBJDUMP -CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 -//Platform information initialized -CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_RANLIB -CMAKE_RANLIB-ADVANCED:INTERNAL=1 -//Path to CMake installation. -CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.10 -//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS -CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG -CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL -CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE -CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO -CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH -CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_SKIP_RPATH -CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS -CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG -CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL -CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE -CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO -CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CMAKE_STRIP -CMAKE_STRIP-ADVANCED:INTERNAL=1 -//uname command -CMAKE_UNAME:INTERNAL=/bin/uname -//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE -CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CURSES_CURSES_LIBRARY -CURSES_CURSES_LIBRARY-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CURSES_FORM_LIBRARY -CURSES_FORM_LIBRARY-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CURSES_INCLUDE_PATH -CURSES_INCLUDE_PATH-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: CURSES_NCURSES_LIBRARY -CURSES_NCURSES_LIBRARY-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: DOXYGEN_DOT_EXECUTABLE -DOXYGEN_DOT_EXECUTABLE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: DOXYGEN_EXECUTABLE -DOXYGEN_EXECUTABLE-ADVANCED:INTERNAL=1 -//Details about finding OpenSSL -FIND_PACKAGE_MESSAGE_DETAILS_OpenSSL:INTERNAL=[/usr/lib/x86_64-linux-gnu/libcrypto.a][/usr/include][v1.1.0g()] -//Details about finding Perl -FIND_PACKAGE_MESSAGE_DETAILS_Perl:INTERNAL=[/usr/bin/perl][v5.26.1()] -//Details about finding Readline -FIND_PACKAGE_MESSAGE_DETAILS_Readline:INTERNAL=[/usr/include][/usr/lib/x86_64-linux-gnu/libreadline.so][v()] -//Details about finding Threads -FIND_PACKAGE_MESSAGE_DETAILS_Threads:INTERNAL=[TRUE][v()] -//Details about finding ZLIB -FIND_PACKAGE_MESSAGE_DETAILS_ZLIB:INTERNAL=[/usr/lib/x86_64-linux-gnu/libz.so][/usr/include][v1.2.11()] -//ADVANCED property for variable: GIT_EXECUTABLE -GIT_EXECUTABLE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: OPENSSL_CRYPTO_LIBRARY -OPENSSL_CRYPTO_LIBRARY-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: OPENSSL_INCLUDE_DIR -OPENSSL_INCLUDE_DIR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: OPENSSL_SSL_LIBRARY -OPENSSL_SSL_LIBRARY-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: PERL_EXECUTABLE -PERL_EXECUTABLE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: PKG_CONFIG_EXECUTABLE -PKG_CONFIG_EXECUTABLE-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Readline_INCLUDE_DIR -Readline_INCLUDE_DIR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Readline_LIBRARY -Readline_LIBRARY-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: Readline_ROOT_DIR -Readline_ROOT_DIR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: ZLIB_INCLUDE_DIR -ZLIB_INCLUDE_DIR-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: ZLIB_LIBRARY_DEBUG -ZLIB_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 -//ADVANCED property for variable: ZLIB_LIBRARY_RELEASE -ZLIB_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 -//Last used BOOST_ROOT value. -_BOOST_ROOT_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0 -//Components requested for this build tree. -_Boost_COMPONENTS_SEARCHED:INTERNAL=chrono;context;coroutine;date_time;filesystem;iostreams;locale;program_options;serialization;signals;system;thread;unit_test_framework -//Last used Boost_INCLUDE_DIR value. -_Boost_INCLUDE_DIR_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/include -//Last used Boost_LIBRARY_DIR_DEBUG value. -_Boost_LIBRARY_DIR_DEBUG_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib -//Last used Boost_LIBRARY_DIR value. -_Boost_LIBRARY_DIR_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib -//Last used Boost_LIBRARY_DIR_RELEASE value. -_Boost_LIBRARY_DIR_RELEASE_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib -//Last used Boost_NAMESPACE value. -_Boost_NAMESPACE_LAST:INTERNAL=boost -//Last used Boost_USE_MULTITHREADED value. -_Boost_USE_MULTITHREADED_LAST:INTERNAL=TRUE -//Last used Boost_USE_STATIC_LIBS value. -_Boost_USE_STATIC_LIBS_LAST:INTERNAL=ON -_OPENSSL_CFLAGS:INTERNAL= -_OPENSSL_CFLAGS_I:INTERNAL= -_OPENSSL_CFLAGS_OTHER:INTERNAL= -_OPENSSL_FOUND:INTERNAL=1 -_OPENSSL_INCLUDEDIR:INTERNAL=/usr/include -_OPENSSL_INCLUDE_DIRS:INTERNAL= -_OPENSSL_LDFLAGS:INTERNAL=-lssl;-lcrypto -_OPENSSL_LDFLAGS_OTHER:INTERNAL= -_OPENSSL_LIBDIR:INTERNAL=/usr/lib/x86_64-linux-gnu -_OPENSSL_LIBRARIES:INTERNAL=ssl;crypto -_OPENSSL_LIBRARY_DIRS:INTERNAL= -_OPENSSL_LIBS:INTERNAL= -_OPENSSL_LIBS_L:INTERNAL= -_OPENSSL_LIBS_OTHER:INTERNAL= -_OPENSSL_LIBS_PATHS:INTERNAL= -_OPENSSL_PREFIX:INTERNAL=/usr -_OPENSSL_STATIC_CFLAGS:INTERNAL= -_OPENSSL_STATIC_CFLAGS_I:INTERNAL= -_OPENSSL_STATIC_CFLAGS_OTHER:INTERNAL= -_OPENSSL_STATIC_INCLUDE_DIRS:INTERNAL= -_OPENSSL_STATIC_LDFLAGS:INTERNAL=-lssl;-ldl;-lcrypto;-ldl -_OPENSSL_STATIC_LDFLAGS_OTHER:INTERNAL= -_OPENSSL_STATIC_LIBDIR:INTERNAL= -_OPENSSL_STATIC_LIBRARIES:INTERNAL=ssl;dl;crypto;dl -_OPENSSL_STATIC_LIBRARY_DIRS:INTERNAL= -_OPENSSL_STATIC_LIBS:INTERNAL= -_OPENSSL_STATIC_LIBS_L:INTERNAL= -_OPENSSL_STATIC_LIBS_OTHER:INTERNAL= -_OPENSSL_STATIC_LIBS_PATHS:INTERNAL= -_OPENSSL_VERSION:INTERNAL=1.1.0g -_OPENSSL_openssl_INCLUDEDIR:INTERNAL= -_OPENSSL_openssl_LIBDIR:INTERNAL= -_OPENSSL_openssl_PREFIX:INTERNAL= -_OPENSSL_openssl_VERSION:INTERNAL= -__pkg_config_arguments__OPENSSL:INTERNAL=QUIET;openssl -__pkg_config_checked__OPENSSL:INTERNAL=1 -prefix_result:INTERNAL=/usr/lib/x86_64-linux-gnu - diff --git a/clang-format.sh b/clang-format.sh new file mode 100755 index 00000000..6ab95eb9 --- /dev/null +++ b/clang-format.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +find ./libraries/plugins/peerplays_sidechain -regex ".*[c|h]pp" | xargs clang-format -i + 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 eb36cd9f..eee02ea4 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 46ebab04..6b95c937 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -381,7 +381,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 836af71e..eb117b32 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -235,6 +235,17 @@ 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; @@ -893,7 +904,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; @@ -930,7 +943,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); @@ -1101,7 +1114,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); @@ -1551,7 +1566,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; @@ -1613,7 +1630,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) ); @@ -1732,7 +1751,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 @@ -1808,7 +1829,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 @@ -2562,18 +2585,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) @@ -2583,7 +2596,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(); @@ -2594,9 +2606,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; @@ -2928,7 +2940,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); @@ -2948,7 +2962,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); @@ -2974,7 +2990,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); @@ -3001,7 +3019,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); @@ -3021,7 +3041,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); @@ -3045,7 +3067,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); @@ -3080,7 +3104,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); @@ -3101,7 +3127,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); @@ -3123,7 +3151,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); 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/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 0c7a458d..0591da54 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -597,7 +597,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 57a72e7f..78740c9b 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,6 +315,38 @@ 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; +} + bool database::is_asset_creation_allowed(const string &symbol) { time_point_sec now = head_block_time(); 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 0d585605..3f68d598 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 { @@ -84,7 +84,7 @@ vector> database::sort_votable_objects< std::vector> refs; for( auto& son : all_sons ) { - if(son.has_valid_config() && son.status != son_status::deregistered) + if(son.has_valid_config(head_block_time()) && son.status != son_status::deregistered) { refs.push_back(std::cref(son)); } @@ -210,20 +210,29 @@ void database::pay_sons() if( now < HARDFORK_SON2_TIME ) { son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id]); } - weighted_total_txs_signed += (s.txs_signed * son_weight); + uint64_t txs_signed = 0; + for (const auto &ts : s.txs_signed) { + txs_signed = txs_signed + ts.second; + } + weighted_total_txs_signed += (txs_signed * son_weight); }); // Now pay off each SON proportional to the number of transactions signed. get_index_type().inspect_all_objects([this, &weighted_total_txs_signed, &dpo, &son_budget, &get_weight, &get_weight_before_son2_hf, &now](const object& o) { const son_statistics_object& s = static_cast(o); - if(s.txs_signed > 0){ + uint64_t txs_signed = 0; + for (const auto &ts : s.txs_signed) { + txs_signed = txs_signed + ts.second; + } + + if(txs_signed > 0){ const auto& idx = get_index_type().indices().get(); auto son_obj = idx.find( s.owner ); auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id]); if( now < HARDFORK_SON2_TIME ) { son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id]); } - share_type pay = (s.txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed; + share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed; modify( *son_obj, [&]( son_object& _son_obj) { _son_obj.pay_son_fee(pay, *this); @@ -236,8 +245,9 @@ void database::pay_sons() //Reset the tx counter in each son statistics object modify( s, [&]( son_statistics_object& _s) { - _s.total_txs_signed += _s.txs_signed; - _s.txs_signed = 0; + for (const auto &ts : s.txs_signed) { + _s.txs_signed.at(ts.first) = 0; + } }); } }); @@ -267,11 +277,13 @@ void database::update_son_metrics(const vector& curr_active_sons) bool is_active_son = (std::find(current_sons.begin(), current_sons.end(), son.id) != current_sons.end()); modify( stats, [&]( son_statistics_object& _stats ) { + if(is_active_son) { + _stats.total_voted_time = _stats.total_voted_time + get_global_properties().parameters.maintenance_interval; + } _stats.total_downtime += _stats.current_interval_downtime; _stats.current_interval_downtime = 0; - if(is_active_son) - { - _stats.total_voted_time = _stats.total_voted_time + get_global_properties().parameters.maintenance_interval; + for (const auto &str : _stats.sidechain_txs_reported) { + _stats.sidechain_txs_reported.at(str.first) = 0; } }); } @@ -593,7 +605,7 @@ void database::update_active_committee_members() update_committee_member_total_votes( cm ); } } - + // Update committee authorities if( !committee_members.empty() ) { @@ -1206,7 +1218,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(); @@ -1244,13 +1255,13 @@ double database::calculate_vesting_factor(const account_object& stake_account) // variables needed const auto number_of_subperiods = vesting_period / vesting_subperiod; double vesting_factor; - + // get in what sub period we are uint32_t current_subperiod = get_gpos_current_subperiod(); - + if(current_subperiod == 0 || current_subperiod > number_of_subperiods) return 0; - // On starting new vesting period, all votes become zero until someone votes, To avoid a situation of zero votes, + // On starting new vesting period, all votes become zero until someone votes, To avoid a situation of zero votes, // changes were done to roll in GPOS rules, the vesting factor will be 1 for whoever votes in 6th sub-period of last vesting period // BLOCKBACK-174 fix if(current_subperiod == 1 && this->head_block_time() >= HARDFORK_GPOS_TIME + vesting_period) //Applicable only from 2nd vesting period @@ -1399,7 +1410,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)); @@ -1414,22 +1424,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) @@ -1883,7 +1877,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; @@ -1944,10 +1937,7 @@ void database::perform_son_tasks() a.options.market_fee_percent = 500; // 5% a.options.issuer_permissions = UIA_ASSET_ISSUER_PERMISSION_MASK; a.options.flags = asset_issuer_permission_flags::charge_market_fee | - //asset_issuer_permission_flags::white_list | - asset_issuer_permission_flags::override_authority | - asset_issuer_permission_flags::transfer_restricted | - asset_issuer_permission_flags::disable_confidential; + asset_issuer_permission_flags::override_authority; a.options.core_exchange_rate.base.amount = 100000; a.options.core_exchange_rate.base.asset_id = asset_id_type(0); a.options.core_exchange_rate.quote.amount = 2500; // CoinMarketCap approx value @@ -1964,6 +1954,74 @@ void database::perform_son_tasks() gpo.pending_parameters->extensions.value.btc_asset = btc_asset.get_id(); }); } + // create HBD asset here because son_account is the issuer of the HBD + if (gpo.parameters.hbd_asset() == asset_id_type() && head_block_time() >= HARDFORK_SON_FOR_HIVE_TIME) + { + const asset_dynamic_data_object& dyn_asset = + create([](asset_dynamic_data_object& a) { + a.current_supply = 0; + }); + + const asset_object& hbd_asset = + create( [&gpo, &dyn_asset]( asset_object& a ) { + a.symbol = "HBD"; + a.precision = 3; + a.issuer = gpo.parameters.son_account(); + a.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; + a.options.market_fee_percent = 500; // 5% + a.options.issuer_permissions = UIA_ASSET_ISSUER_PERMISSION_MASK; + a.options.flags = asset_issuer_permission_flags::charge_market_fee | + asset_issuer_permission_flags::override_authority; + a.options.core_exchange_rate.base.amount = 100000; + a.options.core_exchange_rate.base.asset_id = asset_id_type(0); + a.options.core_exchange_rate.quote.amount = 2500; // CoinMarketCap approx value + a.options.core_exchange_rate.quote.asset_id = a.id; + a.options.whitelist_authorities.clear(); // accounts allowed to use asset, if not empty + a.options.blacklist_authorities.clear(); // accounts who can blacklist other accounts to use asset, if white_list flag is set + a.options.whitelist_markets.clear(); // might be traded with + a.options.blacklist_markets.clear(); // might not be traded with + a.dynamic_asset_data_id = dyn_asset.id; + }); + modify( gpo, [&hbd_asset]( global_property_object& gpo ) { + gpo.parameters.extensions.value.hbd_asset = hbd_asset.get_id(); + if( gpo.pending_parameters ) + gpo.pending_parameters->extensions.value.hbd_asset = hbd_asset.get_id(); + }); + } + // create HIVE asset here because son_account is the issuer of the HIVE + if (gpo.parameters.hive_asset() == asset_id_type() && head_block_time() >= HARDFORK_SON_FOR_HIVE_TIME) + { + const asset_dynamic_data_object& dyn_asset = + create([](asset_dynamic_data_object& a) { + a.current_supply = 0; + }); + + const asset_object& hive_asset = + create( [&gpo, &dyn_asset]( asset_object& a ) { + a.symbol = "HIVE"; + a.precision = 3; + a.issuer = gpo.parameters.son_account(); + a.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; + a.options.market_fee_percent = 500; // 5% + a.options.issuer_permissions = UIA_ASSET_ISSUER_PERMISSION_MASK; + a.options.flags = asset_issuer_permission_flags::charge_market_fee | + asset_issuer_permission_flags::override_authority; + a.options.core_exchange_rate.base.amount = 100000; + a.options.core_exchange_rate.base.asset_id = asset_id_type(0); + a.options.core_exchange_rate.quote.amount = 2500; // CoinMarketCap approx value + a.options.core_exchange_rate.quote.asset_id = a.id; + a.options.whitelist_authorities.clear(); // accounts allowed to use asset, if not empty + a.options.blacklist_authorities.clear(); // accounts who can blacklist other accounts to use asset, if white_list flag is set + a.options.whitelist_markets.clear(); // might be traded with + a.options.blacklist_markets.clear(); // might not be traded with + a.dynamic_asset_data_id = dyn_asset.id; + }); + modify( gpo, [&hive_asset]( global_property_object& gpo ) { + gpo.parameters.extensions.value.hive_asset = hive_asset.get_id(); + if( gpo.pending_parameters ) + gpo.pending_parameters->extensions.value.hive_asset = hive_asset.get_id(); + }); + } // Pay the SONs if (head_block_time() >= HARDFORK_SON_TIME) { @@ -2024,7 +2082,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 = @@ -2036,19 +2094,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 ) @@ -2145,7 +2191,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g } } } tally_helper(*this, gpo); - + perform_account_maintenance( tally_helper ); struct clear_canary { clear_canary(vector& target): target(target){} @@ -2191,7 +2237,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g if( !p.pending_parameters->extensions.value.gpos_subperiod.valid() ) p.pending_parameters->extensions.value.gpos_subperiod = p.parameters.extensions.value.gpos_subperiod; if( !p.pending_parameters->extensions.value.gpos_vesting_lockin_period.valid() ) - p.pending_parameters->extensions.value.gpos_vesting_lockin_period = p.parameters.extensions.value.gpos_vesting_lockin_period; + p.pending_parameters->extensions.value.gpos_vesting_lockin_period = p.parameters.extensions.value.gpos_vesting_lockin_period; if( !p.pending_parameters->extensions.value.rbac_max_permissions_per_account.valid() ) p.pending_parameters->extensions.value.rbac_max_permissions_per_account = p.parameters.extensions.value.rbac_max_permissions_per_account; if( !p.pending_parameters->extensions.value.rbac_max_account_authority_lifetime.valid() ) @@ -2224,6 +2270,10 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g p.pending_parameters->extensions.value.btc_asset = p.parameters.extensions.value.btc_asset; if( !p.pending_parameters->extensions.value.maximum_son_count.valid() ) p.pending_parameters->extensions.value.maximum_son_count = p.parameters.extensions.value.maximum_son_count; + if( !p.pending_parameters->extensions.value.hbd_asset.valid() ) + p.pending_parameters->extensions.value.hbd_asset = p.parameters.extensions.value.hbd_asset; + if( !p.pending_parameters->extensions.value.hive_asset.valid() ) + p.pending_parameters->extensions.value.hive_asset = p.parameters.extensions.value.hive_asset; p.parameters = std::move(*p.pending_parameters); p.pending_parameters.reset(); } 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/hardfork.d/NFT.hf b/libraries/chain/hardfork.d/NFT.hf index 0a540a33..7ab75966 100644 --- a/libraries/chain/hardfork.d/NFT.hf +++ b/libraries/chain/hardfork.d/NFT.hf @@ -1,4 +1,4 @@ -// GPOS HARDFORK 2020-12-21 00:00:00 GMT +// NFT HARDFORK 2020-12-21 00:00:00 GMT #ifndef HARDFORK_NFT_TIME #define HARDFORK_NFT_TIME (fc::time_point_sec( 1608508800 )) -#endif +#endif \ No newline at end of file diff --git a/libraries/chain/hardfork.d/SON.hf b/libraries/chain/hardfork.d/SON.hf index ee75fbe8..4c951f89 100644 --- a/libraries/chain/hardfork.d/SON.hf +++ b/libraries/chain/hardfork.d/SON.hf @@ -1,4 +1,4 @@ -// GPOS HARDFORK 2020-12-21 00:00:00 GMT +// SON HARDFORK HARDFORK 2020-12-21 00:00:00 GMT #ifndef HARDFORK_SON_TIME #define HARDFORK_SON_TIME (fc::time_point_sec( 1608508800 )) #endif diff --git a/libraries/chain/hardfork.d/SON_FOR_HIVE.hf b/libraries/chain/hardfork.d/SON_FOR_HIVE.hf new file mode 100644 index 00000000..8457636b --- /dev/null +++ b/libraries/chain/hardfork.d/SON_FOR_HIVE.hf @@ -0,0 +1,4 @@ +// Saturday, December 11, 2021 0:00:00 +#ifndef HARDFORK_SON_FOR_HIVE_TIME +#define HARDFORK_SON_FOR_HIVE_TIME (fc::time_point_sec( 1639180800 )) +#endif 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 8c467ac0..50975174 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 //////////////////// @@ -325,6 +326,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/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index c24a0576..3a11e99f 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -68,6 +68,8 @@ namespace graphene { namespace chain { optional < account_id_type > son_account = GRAPHENE_NULL_ACCOUNT; optional < asset_id_type > btc_asset = asset_id_type(); optional < uint16_t > maximum_son_count = GRAPHENE_DEFAULT_MAX_SONS; ///< maximum number of active SONS + optional < asset_id_type > hbd_asset = asset_id_type(); + optional < asset_id_type > hive_asset = asset_id_type(); }; struct chain_parameters @@ -212,6 +214,12 @@ namespace graphene { namespace chain { inline uint16_t maximum_son_count()const { return extensions.value.maximum_son_count.valid() ? *extensions.value.maximum_son_count : GRAPHENE_DEFAULT_MAX_SONS; } + inline asset_id_type hbd_asset() const { + return extensions.value.hbd_asset.valid() ? *extensions.value.hbd_asset : asset_id_type(); + } + inline asset_id_type hive_asset() const { + return extensions.value.hive_asset.valid() ? *extensions.value.hive_asset : asset_id_type(); + } private: static void safe_copy(chain_parameters& to, const chain_parameters& from); }; @@ -247,6 +255,8 @@ FC_REFLECT( graphene::chain::parameter_extension, (son_account) (btc_asset) (maximum_son_count) + (hbd_asset) + (hive_asset) ) FC_REFLECT( graphene::chain::chain_parameters, 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_defs.hpp b/libraries/chain/include/graphene/chain/sidechain_defs.hpp index 6bbc8b5c..7f986f96 100644 --- a/libraries/chain/include/graphene/chain/sidechain_defs.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_defs.hpp @@ -9,7 +9,8 @@ enum class sidechain_type { bitcoin, ethereum, eos, - peerplays + peerplays, + hive }; } } @@ -19,4 +20,5 @@ FC_REFLECT_ENUM(graphene::chain::sidechain_type, (bitcoin) (ethereum) (eos) + (hive) (peerplays) ) diff --git a/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp b/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp index e9011ffb..30a0dd5e 100644 --- a/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp @@ -26,7 +26,8 @@ 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; + time_point_sec timestamp; + sidechain_type sidechain = sidechain_type::unknown; object_id_type object_id; std::string transaction; std::vector signers; @@ -37,7 +38,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; @@ -70,6 +71,7 @@ FC_REFLECT_ENUM( graphene::chain::sidechain_transaction_status, (settled) ) FC_REFLECT_DERIVED( graphene::chain::sidechain_transaction_object, (graphene::db::object ), + (timestamp) (sidechain) (object_id) (transaction) diff --git a/libraries/chain/include/graphene/chain/son_object.hpp b/libraries/chain/include/graphene/chain/son_object.hpp index 53072515..d0b74e79 100644 --- a/libraries/chain/include/graphene/chain/son_object.hpp +++ b/libraries/chain/include/graphene/chain/son_object.hpp @@ -31,9 +31,9 @@ namespace graphene { namespace chain { son_id_type owner; // Lifetime total transactions signed - uint64_t total_txs_signed = 0; + flat_map total_txs_signed; // Transactions signed since the last son payouts - uint64_t txs_signed = 0; + flat_map txs_signed; // Total Voted Active time i.e. duration selected as part of voted active SONs uint64_t total_voted_time = 0; // Total Downtime barring the current down time in seconds, used for stats to present to user @@ -47,9 +47,9 @@ namespace graphene { namespace chain { // Deregistered Timestamp fc::time_point_sec deregistered_timestamp; // Total sidechain transactions reported by SON network while SON was active - uint64_t total_sidechain_txs_reported = 0; + flat_map total_sidechain_txs_reported; // Sidechain transactions reported by this SON - uint64_t sidechain_txs_reported = 0; + flat_map sidechain_txs_reported; }; /** @@ -76,6 +76,7 @@ namespace graphene { namespace chain { void pay_son_fee(share_type pay, database& db); bool has_valid_config()const; + bool has_valid_config(time_point_sec head_block_time)const; }; struct by_account; 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/memo.cpp b/libraries/chain/protocol/memo.cpp index afa0b486..1602ae77 100644 --- a/libraries/chain/protocol/memo.cpp +++ b/libraries/chain/protocol/memo.cpp @@ -30,7 +30,7 @@ namespace graphene { namespace chain { void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::public_key& pub, const string& msg, uint64_t custom_nonce) { - if( priv != fc::ecc::private_key() && public_key_type(pub) != public_key_type() ) + if( priv != fc::ecc::private_key() && pub.valid() ) { from = priv.get_public_key(); to = pub; @@ -57,7 +57,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub string memo_data::get_message(const fc::ecc::private_key& priv, const fc::ecc::public_key& pub)const { - if( from != public_key_type() ) + if( from != public_key_type() && pub.valid() ) { auto secret = priv.get_shared_secret(pub); auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str()); 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/sidechain_address_evaluator.cpp b/libraries/chain/sidechain_address_evaluator.cpp index ae802627..625ef2f0 100644 --- a/libraries/chain/sidechain_address_evaluator.cpp +++ b/libraries/chain/sidechain_address_evaluator.cpp @@ -9,7 +9,9 @@ namespace graphene { namespace chain { void_result add_sidechain_address_evaluator::do_evaluate(const sidechain_address_add_operation& op) { try{ - FC_ASSERT( op.deposit_public_key.length() > 0 && op.deposit_address.length() == 0 && op.deposit_address_data.length() == 0, "User should add a valid deposit public key and a null deposit address"); + if (op.sidechain == sidechain_type::bitcoin) { + FC_ASSERT( op.deposit_public_key.length() > 0 && op.deposit_address.length() == 0 && op.deposit_address_data.length() == 0, "ser should add a valid deposit public key and a null deposit address (Bitcoin only)"); + } const auto& sdpke_idx = db().get_index_type().indices().get(); FC_ASSERT( sdpke_idx.find(boost::make_tuple(op.sidechain, op.deposit_public_key, time_point_sec::maximum())) == sdpke_idx.end(), "An active deposit key already exists" ); return void_result(); @@ -31,8 +33,8 @@ object_id_type add_sidechain_address_evaluator::do_apply(const sidechain_address obj.sidechain_address_account = op.sidechain_address_account; obj.sidechain = op.sidechain; obj.deposit_public_key = op.deposit_public_key; - obj.deposit_address = ""; - obj.deposit_address_data = ""; + obj.deposit_address = op.deposit_address; + obj.deposit_address_data = op.deposit_address_data; obj.withdraw_public_key = op.withdraw_public_key; obj.withdraw_address = op.withdraw_address; obj.valid_from = db().head_block_time(); diff --git a/libraries/chain/sidechain_transaction_evaluator.cpp b/libraries/chain/sidechain_transaction_evaluator.cpp index 12bf2f42..ba256199 100644 --- a/libraries/chain/sidechain_transaction_evaluator.cpp +++ b/libraries/chain/sidechain_transaction_evaluator.cpp @@ -28,6 +28,7 @@ void_result sidechain_transaction_create_evaluator::do_evaluate(const sidechain_ object_id_type sidechain_transaction_create_evaluator::do_apply(const sidechain_transaction_create_operation &op) { try { const auto &new_sidechain_transaction_object = db().create([&](sidechain_transaction_object &sto) { + sto.timestamp = db().head_block_time(); sto.sidechain = op.sidechain; sto.object_id = op.object_id; sto.transaction = op.transaction; @@ -97,7 +98,15 @@ object_id_type sidechain_transaction_sign_evaluator::do_apply(const sidechain_tr }); db().modify(son_obj->statistics(db()), [&](son_statistics_object& sso) { - sso.txs_signed += 1; + if (sso.total_txs_signed.find(sto_obj->sidechain) == sso.total_txs_signed.end()) { + sso.total_txs_signed[sto_obj->sidechain] = 0; + } + sso.total_txs_signed[sto_obj->sidechain] += 1; + + if (sso.txs_signed.find(sto_obj->sidechain) == sso.txs_signed.end()) { + sso.txs_signed[sto_obj->sidechain] = 0; + } + sso.txs_signed[sto_obj->sidechain] += 1; }); return op.sidechain_transaction_id; diff --git a/libraries/chain/son_object.cpp b/libraries/chain/son_object.cpp index bf54c833..ae61f682 100644 --- a/libraries/chain/son_object.cpp +++ b/libraries/chain/son_object.cpp @@ -12,4 +12,17 @@ namespace graphene { namespace chain { (sidechain_public_keys.find( sidechain_type::bitcoin ) != sidechain_public_keys.end()) && (sidechain_public_keys.at(sidechain_type::bitcoin).length() > 0)); } + + bool son_object::has_valid_config(time_point_sec head_block_time)const { + bool retval = has_valid_config(); + + if (head_block_time >= HARDFORK_SON_FOR_HIVE_TIME) { + retval = retval && + (sidechain_public_keys.find( sidechain_type::hive ) != sidechain_public_keys.end()) && + (sidechain_public_keys.at(sidechain_type::hive).length() > 0); + } + + return retval; + } + }} diff --git a/libraries/chain/son_wallet_deposit_evaluator.cpp b/libraries/chain/son_wallet_deposit_evaluator.cpp index 24a87e47..f9620282 100644 --- a/libraries/chain/son_wallet_deposit_evaluator.cpp +++ b/libraries/chain/son_wallet_deposit_evaluator.cpp @@ -84,9 +84,16 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de auto stats_itr = db().get_index_type().indices().get().find(si.son_id); db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) { - sso.total_sidechain_txs_reported = sso.total_sidechain_txs_reported + 1; + if (sso.total_sidechain_txs_reported.find(op.sidechain) == sso.total_sidechain_txs_reported.end()) { + sso.total_sidechain_txs_reported[op.sidechain] = 0; + } + sso.total_sidechain_txs_reported[op.sidechain] += 1; + if (si.son_id == op.son_id) { - sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; + if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) { + sso.sidechain_txs_reported[op.sidechain] = 0; + } + sso.sidechain_txs_reported[op.sidechain] += 1; } }); } @@ -122,7 +129,10 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de }); auto stats_itr = db().get_index_type().indices().get().find(op.son_id); db().modify(*stats_itr, [&op](son_statistics_object &sso) { - sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; + if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) { + sso.sidechain_txs_reported[op.sidechain] = 0; + } + sso.sidechain_txs_reported[op.sidechain] += 1; }); return (*itr).id; } diff --git a/libraries/chain/son_wallet_withdraw_evaluator.cpp b/libraries/chain/son_wallet_withdraw_evaluator.cpp index bf6adaf9..2110e49d 100644 --- a/libraries/chain/son_wallet_withdraw_evaluator.cpp +++ b/libraries/chain/son_wallet_withdraw_evaluator.cpp @@ -82,9 +82,16 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w auto stats_itr = db().get_index_type().indices().get().find(si.son_id); db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) { - sso.total_sidechain_txs_reported = sso.total_sidechain_txs_reported + 1; + if (sso.total_sidechain_txs_reported.find(op.sidechain) == sso.total_sidechain_txs_reported.end()) { + sso.total_sidechain_txs_reported[op.sidechain] = 0; + } + sso.total_sidechain_txs_reported[op.sidechain] += 1; + if (si.son_id == op.son_id) { - sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; + if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) { + sso.sidechain_txs_reported[op.sidechain] = 0; + } + sso.sidechain_txs_reported[op.sidechain] += 1; } }); } @@ -120,7 +127,10 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w }); auto stats_itr = db().get_index_type().indices().get().find(op.son_id); db().modify(*stats_itr, [&op](son_statistics_object &sso) { - sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; + if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) { + sso.sidechain_txs_reported[op.sidechain] = 0; + } + sso.sidechain_txs_reported[op.sidechain] += 1; }); return (*itr).id; } 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/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..bb74df29 100755 --- a/libraries/plugins/peerplays_sidechain/CMakeLists.txt +++ b/libraries/plugins/peerplays_sidechain/CMakeLists.txt @@ -5,6 +5,7 @@ add_library( peerplays_sidechain sidechain_net_manager.cpp sidechain_net_handler.cpp sidechain_net_handler_bitcoin.cpp + sidechain_net_handler_hive.cpp sidechain_net_handler_peerplays.cpp bitcoin/bech32.cpp bitcoin/bitcoin_address.cpp @@ -13,6 +14,12 @@ add_library( peerplays_sidechain bitcoin/segwit_addr.cpp bitcoin/utils.cpp bitcoin/sign_bitcoin_transaction.cpp + common/rpc_client.cpp + common/utils.cpp + hive/asset.cpp + hive/operations.cpp + hive/transaction.cpp + hive/types.cpp ) if (ENABLE_DEV_FEATURES) @@ -36,7 +43,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 curl 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..50c02964 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp @@ -1,3 +1,4 @@ +#include #include #include 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/common/rpc_client.cpp b/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp new file mode 100644 index 00000000..ce4081c2 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp @@ -0,0 +1,185 @@ +#include + +#include +#include + +#include +#include + +#include + +#include +#include + +namespace graphene { namespace peerplays_sidechain { + +rpc_client::rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls) : + ip(_ip), + port(_port), + user(_user), + password(_password), + debug_rpc_calls(_debug_rpc_calls), + request_id(0) { + authorization.key = "Authorization"; + authorization.val = "Basic " + fc::base64_encode(user + ":" + password); +} + +std::string rpc_client::retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx) { + std::stringstream ss(reply_str); + boost::property_tree::ptree json; + boost::property_tree::read_json(ss, json); + if (json.find("result") == json.not_found()) { + return ""; + } + auto json_result = json.get_child("result"); + if (json_result.find(array_path) == json_result.not_found()) { + return ""; + } + + boost::property_tree::ptree array_ptree = json_result; + if (!array_path.empty()) { + array_ptree = json_result.get_child(array_path); + } + uint32_t array_el_idx = -1; + for (const auto &array_el : array_ptree) { + array_el_idx = array_el_idx + 1; + if (array_el_idx == idx) { + std::stringstream ss_res; + boost::property_tree::json_parser::write_json(ss_res, array_el.second); + return ss_res.str(); + } + } + + return ""; +} + +std::string rpc_client::retrieve_value_from_reply(std::string reply_str, std::string value_path) { + std::stringstream ss(reply_str); + boost::property_tree::ptree json; + boost::property_tree::read_json(ss, json); + if (json.find("result") == json.not_found()) { + return ""; + } + auto json_result = json.get_child("result"); + if (json_result.find(value_path) == json_result.not_found()) { + return ""; + } + return json_result.get(value_path); +} + +std::string rpc_client::send_post_request(std::string method, std::string params, bool show_log) { + std::stringstream body; + + request_id = request_id + 1; + + body << "{ \"jsonrpc\": \"2.0\", \"id\": " << request_id << ", \"method\": \"" << method << "\""; + + if (!params.empty()) { + body << ", \"params\": " << params; + } + + body << " }"; + + const auto reply = send_post_request(body.str(), show_log); + + if (reply.body.empty()) { + wlog("RPC call ${function} failed", ("function", __FUNCTION__)); + return ""; + } + + std::stringstream ss(std::string(reply.body.begin(), reply.body.end())); + boost::property_tree::ptree json; + boost::property_tree::read_json(ss, json); + + if (reply.status == 200) { + return ss.str(); + } + + if (json.count("error") && !json.get_child("error").empty()) { + wlog("RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body.str())("msg", ss.str())); + } + return ""; +} + +//fc::http::reply rpc_client::send_post_request(std::string body, bool show_log) { +// fc::http::connection conn; +// conn.connect_to(fc::ip::endpoint(fc::ip::address(ip), port)); +// +// std::string url = "http://" + ip + ":" + std::to_string(port); +// +// //if (wallet.length() > 0) { +// // url = url + "/wallet/" + wallet; +// //} +// +// fc::http::reply reply = conn.request("POST", url, body, fc::http::headers{authorization}); +// +// if (show_log) { +// ilog("### Request URL: ${url}", ("url", url)); +// ilog("### Request: ${body}", ("body", body)); +// std::stringstream ss(std::string(reply.body.begin(), reply.body.end())); +// ilog("### Response: ${ss}", ("ss", ss.str())); +// } +// +// return reply; +//} + +static size_t write_callback(char *ptr, size_t size, size_t nmemb, rpc_reply *reply) { + size_t retval = 0; + if (reply != nullptr) { + reply->body.append(ptr, size * nmemb); + retval = size * nmemb; + } + return retval; +} + +rpc_reply rpc_client::send_post_request(std::string body, bool show_log) { + + struct curl_slist *headers = nullptr; + headers = curl_slist_append(headers, "Accept: application/json"); + headers = curl_slist_append(headers, "Content-Type: application/json"); + headers = curl_slist_append(headers, "charset: utf-8"); + + CURL *curl = curl_easy_init(); + if (ip.find("https://", 0) != 0) { + curl_easy_setopt(curl, CURLOPT_URL, ip.c_str()); + curl_easy_setopt(curl, CURLOPT_PORT, port); + } else { + std::string full_address = ip + ":" + std::to_string(port); + curl_easy_setopt(curl, CURLOPT_URL, full_address.c_str()); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false); + } + if (!user.empty()) { + curl_easy_setopt(curl, CURLOPT_USERNAME, user.c_str()); + curl_easy_setopt(curl, CURLOPT_PASSWORD, password.c_str()); + } + + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str()); + + //curl_easy_setopt(curl, CURLOPT_VERBOSE, true); + + rpc_reply reply; + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &reply); + + curl_easy_perform(curl); + + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &reply.status); + + curl_easy_cleanup(curl); + curl_slist_free_all(headers); + + if (show_log) { + std::string url = ip + ":" + std::to_string(port); + ilog("### Request URL: ${url}", ("url", url)); + ilog("### Request: ${body}", ("body", body)); + std::stringstream ss(std::string(reply.body.begin(), reply.body.end())); + ilog("### Response: ${ss}", ("ss", ss.str())); + } + + return reply; +} + +}} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/common/utils.cpp b/libraries/plugins/peerplays_sidechain/common/utils.cpp new file mode 100644 index 00000000..4491487f --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/common/utils.cpp @@ -0,0 +1,8 @@ +#include + +std::string object_id_to_string(graphene::chain::object_id_type id) { + std::string object_id = fc::to_string(id.space()) + "." + + fc::to_string(id.type()) + "." + + fc::to_string(id.instance()); + return object_id; +} diff --git a/libraries/plugins/peerplays_sidechain/hive/asset.cpp b/libraries/plugins/peerplays_sidechain/hive/asset.cpp new file mode 100644 index 00000000..7417107f --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/hive/asset.cpp @@ -0,0 +1,69 @@ +#include + +#include + +#include +#include + +#define ASSET_AMOUNT_KEY "amount" +#define ASSET_PRECISION_KEY "precision" +#define ASSET_NAI_KEY "nai" + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +uint64_t asset::hbd_symbol_ser = HBD_SYMBOL_SER; +uint64_t asset::hive_symbol_ser = HIVE_SYMBOL_SER; + +}}} // namespace graphene::peerplays_sidechain::hive + +namespace fc { + +void to_variant(const graphene::peerplays_sidechain::hive::asset &var, fc::variant &vo, uint32_t max_depth) { + try { + if (var.symbol == HBD_SYMBOL_SER) { + variant v = mutable_variant_object(ASSET_AMOUNT_KEY, boost::lexical_cast(var.amount.value))(ASSET_PRECISION_KEY, uint64_t(HBD_PRECISION))(ASSET_NAI_KEY, HBD_NAI); + vo = v; + } + if (var.symbol == HIVE_SYMBOL_SER) { + variant v = mutable_variant_object(ASSET_AMOUNT_KEY, boost::lexical_cast(var.amount.value))(ASSET_PRECISION_KEY, uint64_t(HIVE_PRECISION))(ASSET_NAI_KEY, HIVE_NAI); + vo = v; + } + if (var.symbol == TBD_SYMBOL_SER) { + variant v = mutable_variant_object(ASSET_AMOUNT_KEY, boost::lexical_cast(var.amount.value))(ASSET_PRECISION_KEY, uint64_t(TBD_PRECISION))(ASSET_NAI_KEY, TBD_NAI); + vo = v; + } + if (var.symbol == TESTS_SYMBOL_SER) { + variant v = mutable_variant_object(ASSET_AMOUNT_KEY, boost::lexical_cast(var.amount.value))(ASSET_PRECISION_KEY, uint64_t(TESTS_PRECISION))(ASSET_NAI_KEY, TESTS_NAI); + vo = v; + } + } + FC_CAPTURE_AND_RETHROW() +} + +void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::asset &vo, uint32_t max_depth) { + try { + FC_ASSERT(var.is_object(), "Asset has to be treated as object."); + + const auto &v_object = var.get_object(); + + FC_ASSERT(v_object.contains(ASSET_AMOUNT_KEY), "Amount field doesn't exist."); + FC_ASSERT(v_object[ASSET_AMOUNT_KEY].is_string(), "Expected a string type for value '${key}'.", ("key", ASSET_AMOUNT_KEY)); + vo.amount = boost::lexical_cast(v_object[ASSET_AMOUNT_KEY].as(max_depth)); + FC_ASSERT(vo.amount >= 0, "Asset amount cannot be negative"); + + FC_ASSERT(v_object.contains(ASSET_PRECISION_KEY), "Precision field doesn't exist."); + FC_ASSERT(v_object[ASSET_PRECISION_KEY].is_uint64(), "Expected an unsigned integer type for value '${key}'.", ("key", ASSET_PRECISION_KEY)); + + FC_ASSERT(v_object.contains(ASSET_NAI_KEY), "NAI field doesn't exist."); + FC_ASSERT(v_object[ASSET_NAI_KEY].is_string(), "Expected a string type for value '${key}'.", ("key", ASSET_NAI_KEY)); + + if (v_object[ASSET_NAI_KEY].as(max_depth) == HBD_NAI) { + vo.symbol = graphene::peerplays_sidechain::hive::asset::hbd_symbol_ser; + } + if (v_object[ASSET_NAI_KEY].as(max_depth) == HIVE_NAI) { + vo.symbol = graphene::peerplays_sidechain::hive::asset::hive_symbol_ser; + } + } + FC_CAPTURE_AND_RETHROW() +} +} // namespace fc diff --git a/libraries/plugins/peerplays_sidechain/hive/operations.cpp b/libraries/plugins/peerplays_sidechain/hive/operations.cpp new file mode 100644 index 00000000..b21b564e --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/hive/operations.cpp @@ -0,0 +1,101 @@ +#include + +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +}}} // namespace graphene::peerplays_sidechain::hive + +namespace fc { + +static std::string trim_typename_namespace(const std::string &name) { + auto start = name.find_last_of(':'); + start = (start == std::string::npos) ? 0 : start + 1; + return name.substr(start); +} + +struct from_static_variant_for_hive { + fc::variant &var; + from_static_variant_for_hive(fc::variant &dv) : + var(dv) { + } + + typedef void result_type; + template + void operator()(const T &v) const { + auto name = trim_typename_namespace(fc::get_typename::name()); + fc::variant value; + to_variant(v, value, 5); + var = mutable_variant_object("type", name).set("value", value); + } +}; + +struct to_static_variant_for_hive { + const fc::variant &var; + to_static_variant_for_hive(const fc::variant &dv) : + var(dv) { + } + + typedef void result_type; + template + void operator()(T &v) const { + from_variant(var, v, 5); + } +}; + +struct get_static_variant_name { + string &name; + get_static_variant_name(string &n) : + name(n) { + } + + typedef void result_type; + template + void operator()(T &v) const { + name = trim_typename_namespace(fc::get_typename::name()); + } +}; + +void to_variant(const graphene::peerplays_sidechain::hive::hive_operation &var, fc::variant &vo, uint32_t max_depth) { + var.visit(from_static_variant_for_hive(vo)); +} + +void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::hive_operation &vo, uint32_t max_depth) { + static std::map to_tag = []() { + std::map name_map; + for (int i = 0; i < graphene::peerplays_sidechain::hive::hive_operation::count(); ++i) { + graphene::peerplays_sidechain::hive::hive_operation tmp; + tmp.set_which(i); + string n; + tmp.visit(get_static_variant_name(n)); + name_map[n] = i; + } + return name_map; + }(); + + auto ar = var.get_array(); + if (ar.size() < 2) + return; + auto var_second = ar[1]; + + FC_ASSERT(var_second.is_object(), "Input data have to treated as object."); + auto v_object = var_second.get_object(); + + FC_ASSERT(v_object.contains("type"), "Type field doesn't exist."); + FC_ASSERT(v_object.contains("value"), "Value field doesn't exist."); + + int64_t which = -1; + + if (v_object["type"].is_integer()) { + which = v_object["type"].as_int64(); + } else { + auto itr = to_tag.find(v_object["type"].as_string()); + FC_ASSERT(itr != to_tag.end(), "Invalid object name: ${n}", ("n", v_object["type"])); + which = itr->second; + } + + vo.set_which(which); + vo.visit(fc::to_static_variant_for_hive(v_object["value"])); +} + +} // namespace fc diff --git a/libraries/plugins/peerplays_sidechain/hive/transaction.cpp b/libraries/plugins/peerplays_sidechain/hive/transaction.cpp new file mode 100644 index 00000000..3e4a59f5 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/hive/transaction.cpp @@ -0,0 +1,57 @@ +#include + +#include + +#include +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +digest_type transaction::digest() const { + digest_type::encoder enc; + fc::raw::pack(enc, *this); + return enc.result(); +} + +transaction_id_type transaction::id() const { + auto h = digest(); + transaction_id_type result; + memcpy(result._hash, h._hash, std::min(sizeof(result), sizeof(h))); + return result; +} + +digest_type transaction::sig_digest(const chain_id_type &chain_id) const { + digest_type::encoder enc; + fc::raw::pack(enc, chain_id); + fc::raw::pack(enc, *this); + return enc.result(); +} + +void transaction::set_expiration(fc::time_point_sec expiration_time) { + expiration = expiration_time; +} + +void transaction::set_reference_block(const block_id_type &reference_block) { + ref_block_num = fc::endian_reverse_u32(reference_block._hash[0]); + ref_block_prefix = reference_block._hash[1]; +} + +void signed_transaction::clear() { + operations.clear(); + signatures.clear(); +} + +const signature_type &signed_transaction::sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id) { + digest_type h = sig_digest(chain_id); + signatures.push_back(key.sign_compact(h, true)); + return signatures.back(); +} + +signature_type signed_transaction::sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id) const { + digest_type::encoder enc; + fc::raw::pack(enc, chain_id); + fc::raw::pack(enc, *this); + return key.sign_compact(enc.result(), true); +} + +}}} // namespace graphene::peerplays_sidechain::hive diff --git a/libraries/plugins/peerplays_sidechain/hive/types.cpp b/libraries/plugins/peerplays_sidechain/hive/types.cpp new file mode 100644 index 00000000..7a5506e7 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/hive/types.cpp @@ -0,0 +1,73 @@ +#include + +#include +#include +#include +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +std::string public_key_type::prefix = KEY_PREFIX_STM; + +public_key_type::public_key_type() : + key_data(){}; + +public_key_type::public_key_type(const fc::ecc::public_key_data &data) : + key_data(data){}; + +public_key_type::public_key_type(const fc::ecc::public_key &pubkey) : + key_data(pubkey){}; + +public_key_type::public_key_type(const std::string &base58str) { + const size_t prefix_len = prefix.size(); + FC_ASSERT(base58str.size() > prefix_len); + FC_ASSERT(base58str.substr(0, prefix_len) == prefix, "", ("base58str", base58str)); + auto bin = fc::from_base58(base58str.substr(prefix_len)); + auto bin_key = fc::raw::unpack(bin); + key_data = bin_key.data; + FC_ASSERT(fc::ripemd160::hash(key_data.data, key_data.size())._hash[0] == bin_key.check); +}; + +public_key_type::operator fc::ecc::public_key_data() const { + return key_data; +}; + +public_key_type::operator fc::ecc::public_key() const { + return fc::ecc::public_key(key_data); +}; + +public_key_type::operator std::string() const { + binary_key k; + k.data = key_data; + k.check = fc::ripemd160::hash(k.data.data, k.data.size())._hash[0]; + auto data = fc::raw::pack(k); + return prefix + fc::to_base58(data.data(), data.size()); +} + +bool operator==(const public_key_type &p1, const fc::ecc::public_key &p2) { + return p1.key_data == p2.serialize(); +} + +bool operator==(const public_key_type &p1, const public_key_type &p2) { + return p1.key_data == p2.key_data; +} + +bool operator!=(const public_key_type &p1, const public_key_type &p2) { + return p1.key_data != p2.key_data; +} + +}}} // namespace graphene::peerplays_sidechain::hive + +namespace fc { + +using namespace std; + +void to_variant(const graphene::peerplays_sidechain::hive::public_key_type &var, fc::variant &vo, uint32_t max_depth) { + vo = std::string(var); +} + +void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::public_key_type &vo, uint32_t max_depth) { + vo = graphene::peerplays_sidechain::hive::public_key_type(var.as_string()); +} + +} // namespace fc diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/rpc_client.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/rpc_client.hpp new file mode 100644 index 00000000..f61bdb3f --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/rpc_client.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include +#include + +#include + +namespace graphene { namespace peerplays_sidechain { + +struct rpc_reply { + uint16_t status; + std::string body; +}; + +class rpc_client { +public: + rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls); + +protected: + std::string retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx); + std::string retrieve_value_from_reply(std::string reply_str, std::string value_path); + std::string send_post_request(std::string method, std::string params, bool show_log); + + std::string ip; + uint32_t port; + std::string user; + std::string password; + bool debug_rpc_calls; + + uint32_t request_id; + + fc::http::header authorization; + +private: + //fc::http::reply send_post_request(std::string body, bool show_log); + rpc_reply send_post_request(std::string body, bool show_log); +}; + +}} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp new file mode 100644 index 00000000..99c59019 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include + +std::string object_id_to_string(graphene::chain::object_id_type id); diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/asset.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/asset.hpp new file mode 100644 index 00000000..f0743741 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/asset.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +#define HBD_NAI "@@000000013" +#define HBD_PRECISION 3 +#define HBD_SYMBOL_U64 (uint64_t('S') | (uint64_t('B') << 8) | (uint64_t('D') << 16)) +#define HBD_SYMBOL_SER (uint64_t(3) | (HBD_SYMBOL_U64 << 8)) + +#define HIVE_NAI "@@000000021" +#define HIVE_PRECISION 3 +#define HIVE_SYMBOL_U64 (uint64_t('S') | (uint64_t('T') << 8) | (uint64_t('E') << 16) | (uint64_t('E') << 24) | (uint64_t('M') << 32)) +#define HIVE_SYMBOL_SER (uint64_t(3) | (HIVE_SYMBOL_U64 << 8)) + +#define TBD_NAI "@@000000013" +#define TBD_PRECISION 3 +#define TBD_SYMBOL_U64 (uint64_t('T') | (uint64_t('B') << 8) | (uint64_t('D') << 16)) +#define TBD_SYMBOL_SER (uint64_t(3) | (TBD_SYMBOL_U64 << 8)) + +#define TESTS_NAI "@@000000021" +#define TESTS_PRECISION 3 +#define TESTS_SYMBOL_U64 (uint64_t('T') | (uint64_t('E') << 8) | (uint64_t('S') << 16) | (uint64_t('T') << 24) | (uint64_t('S') << 32)) +#define TESTS_SYMBOL_SER (uint64_t(3) | (TESTS_SYMBOL_U64 << 8)) + +struct asset { + static uint64_t hbd_symbol_ser; + static uint64_t hive_symbol_ser; + share_type amount; + uint64_t symbol; +}; + +}}} // namespace graphene::peerplays_sidechain::hive + +namespace fc { +void to_variant(const graphene::peerplays_sidechain::hive::asset &var, fc::variant &vo, uint32_t max_depth); +void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::asset &vo, uint32_t max_depth); +} // namespace fc + +FC_REFLECT(graphene::peerplays_sidechain::hive::asset, (amount)(symbol)) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/authority.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/authority.hpp new file mode 100644 index 00000000..bd67ae23 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/authority.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include + +#include + +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +struct authority { + authority() { + } + + enum classification { + owner = 0, + active = 1, + key = 2, + posting = 3 + }; + + uint32_t weight_threshold = 0; + fc::flat_map account_auths; + fc::flat_map key_auths; +}; + +}}} // namespace graphene::peerplays_sidechain::hive + +FC_REFLECT_ENUM(graphene::peerplays_sidechain::hive::authority::classification, + (owner)(active)(key)(posting)) + +FC_REFLECT(graphene::peerplays_sidechain::hive::authority, + (weight_threshold)(account_auths)(key_auths)) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp new file mode 100644 index 00000000..1348ce35 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp @@ -0,0 +1,123 @@ +#pragma once + +#include +#include + +#include + +#include +#include +#include +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +struct vote_operation {}; +struct comment_operation {}; + +struct transfer_operation { + hive::account_name_type from; + hive::account_name_type to; + hive::asset amount; + std::string memo; +}; + +struct transfer_to_vesting_operation {}; +struct withdraw_vesting_operation {}; +struct limit_order_create_operation {}; +struct limit_order_cancel_operation {}; +struct feed_publish_operation {}; +struct convert_operation {}; +struct account_create_operation {}; + +struct account_update_operation { + hive::account_name_type account; + fc::optional owner; + fc::optional active; + fc::optional posting; + hive::public_key_type memo_key; + std::string json_metadata; +}; + +struct witness_update_operation {}; +struct account_witness_vote_operation {}; +struct account_witness_proxy_operation {}; +struct pow_operation {}; +struct custom_operation {}; +struct report_over_production_operation {}; +struct delete_comment_operation {}; +struct custom_json_operation {}; +struct comment_options_operation {}; +struct set_withdraw_vesting_route_operation {}; +struct limit_order_create2_operation {}; +struct claim_account_operation {}; +struct create_claimed_account_operation {}; +struct request_account_recovery_operation {}; +struct recover_account_operation {}; +struct change_recovery_account_operation {}; +struct escrow_transfer_operation {}; +struct escrow_dispute_operation {}; +struct escrow_release_operation {}; +struct pow2_operation {}; +struct escrow_approve_operation {}; +struct transfer_to_savings_operation {}; +struct transfer_from_savings_operation {}; +struct cancel_transfer_from_savings_operation {}; +struct custom_binary_operation {}; +struct decline_voting_rights_operation {}; +struct reset_account_operation {}; +struct set_reset_account_operation {}; +struct claim_reward_balance_operation {}; + +struct delegate_vesting_shares_operation { + hive::account_name_type delegator; + hive::account_name_type delegatee; + hive::asset vesting_shares; +}; + +}}} // namespace graphene::peerplays_sidechain::hive + +FC_REFLECT(graphene::peerplays_sidechain::hive::vote_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::comment_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_operation, + (from)(to)(amount)(memo)) +FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_to_vesting_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::withdraw_vesting_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::limit_order_create_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::limit_order_cancel_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::feed_publish_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::convert_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::account_create_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::account_update_operation, + (account)(owner)(active)(posting)(memo_key)(json_metadata)) +FC_REFLECT(graphene::peerplays_sidechain::hive::witness_update_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::account_witness_vote_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::account_witness_proxy_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::pow_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::custom_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::report_over_production_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::delete_comment_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::custom_json_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::comment_options_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::set_withdraw_vesting_route_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::limit_order_create2_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::claim_account_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::create_claimed_account_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::request_account_recovery_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::recover_account_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::change_recovery_account_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_transfer_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_dispute_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_release_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::pow2_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_approve_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_to_savings_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_from_savings_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::cancel_transfer_from_savings_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::custom_binary_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::decline_voting_rights_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::reset_account_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::set_reset_account_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::claim_reward_balance_operation, ) +FC_REFLECT(graphene::peerplays_sidechain::hive::delegate_vesting_shares_operation, + (delegator)(delegatee)(vesting_shares)) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/operations.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/operations.hpp new file mode 100644 index 00000000..e64eb1ae --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/operations.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +typedef fc::static_variant< + vote_operation, + comment_operation, + + transfer_operation, + transfer_to_vesting_operation, + withdraw_vesting_operation, + + limit_order_create_operation, + limit_order_cancel_operation, + + feed_publish_operation, + convert_operation, + + account_create_operation, + account_update_operation, + + witness_update_operation, + account_witness_vote_operation, + account_witness_proxy_operation, + + pow_operation, + + custom_operation, + + report_over_production_operation, + + delete_comment_operation, + custom_json_operation, + comment_options_operation, + set_withdraw_vesting_route_operation, + limit_order_create2_operation, + claim_account_operation, + create_claimed_account_operation, + request_account_recovery_operation, + recover_account_operation, + change_recovery_account_operation, + escrow_transfer_operation, + escrow_dispute_operation, + escrow_release_operation, + pow2_operation, + escrow_approve_operation, + transfer_to_savings_operation, + transfer_from_savings_operation, + cancel_transfer_from_savings_operation, + custom_binary_operation, + decline_voting_rights_operation, + reset_account_operation, + set_reset_account_operation, + claim_reward_balance_operation, + delegate_vesting_shares_operation> + hive_operation; + +}}} // namespace graphene::peerplays_sidechain::hive + +namespace fc { + +void to_variant(const graphene::peerplays_sidechain::hive::hive_operation &var, fc::variant &vo, uint32_t max_depth = 5); +void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::hive_operation &vo, uint32_t max_depth = 5); + +} // namespace fc + +FC_REFLECT_TYPENAME(graphene::peerplays_sidechain::hive::hive_operation) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/transaction.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/transaction.hpp new file mode 100644 index 00000000..8b35b7b3 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/transaction.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include +#include + +#include +#include + +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +struct transaction { + uint16_t ref_block_num = 0; + uint32_t ref_block_prefix = 0; + fc::time_point_sec expiration; + std::vector operations; + extensions_type extensions; + + digest_type digest() const; + transaction_id_type id() const; + digest_type sig_digest(const chain_id_type &chain_id) const; + + void set_expiration(fc::time_point_sec expiration_time); + void set_reference_block(const block_id_type &reference_block); +}; + +struct signed_transaction : public transaction { + + std::vector signatures; + + const signature_type &sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id); + signature_type sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id) const; + void clear(); +}; + +}}} // namespace graphene::peerplays_sidechain::hive + +FC_REFLECT(graphene::peerplays_sidechain::hive::transaction, + (ref_block_num)(ref_block_prefix)(expiration)(operations)(extensions)) + +FC_REFLECT_DERIVED(graphene::peerplays_sidechain::hive::signed_transaction, + (graphene::peerplays_sidechain::hive::transaction), + (signatures)) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp new file mode 100644 index 00000000..f5b986e4 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include +#include + +namespace graphene { namespace peerplays_sidechain { namespace hive { + +#define KEY_PREFIX_STM "STM" +#define KEY_PREFIX_TST "TST" + +enum network { + mainnet, + testnet +}; + +struct void_t {}; + +typedef fc::static_variant future_extensions; +typedef fc::flat_set extensions_type; + +typedef fc::ecc::private_key private_key_type; +typedef fc::sha256 chain_id_type; +typedef std::string account_name_type; +typedef fc::ripemd160 block_id_type; +//typedef fc::ripemd160 checksum_type; +typedef fc::ripemd160 transaction_id_type; +typedef fc::sha256 digest_type; +typedef fc::ecc::compact_signature signature_type; +typedef fc::safe share_type; +//typedef safe ushare_type; +//typedef uint16_t weight_type; +//typedef uint32_t contribution_id_type; +//typedef fixed_string<32> custom_id_type; + +struct public_key_type { + + static std::string prefix; + + struct binary_key { + binary_key() { + } + uint32_t check = 0; + fc::ecc::public_key_data data; + }; + fc::ecc::public_key_data key_data; + public_key_type(); + public_key_type(const fc::ecc::public_key_data &data); + public_key_type(const fc::ecc::public_key &pubkey); + explicit public_key_type(const std::string &base58str); + operator fc::ecc::public_key_data() const; + operator fc::ecc::public_key() const; + explicit operator std::string() const; + friend bool operator==(const public_key_type &p1, const fc::ecc::public_key &p2); + friend bool operator==(const public_key_type &p1, const public_key_type &p2); + friend bool operator<(const public_key_type &p1, const public_key_type &p2) { + return p1.key_data < p2.key_data; + } + friend bool operator!=(const public_key_type &p1, const public_key_type &p2); +}; + +}}} // namespace graphene::peerplays_sidechain::hive + +namespace fc { +void to_variant(const graphene::peerplays_sidechain::hive::public_key_type &var, fc::variant &vo, uint32_t max_depth = 2); +void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::public_key_type &vo, uint32_t max_depth = 2); +} // namespace fc + +FC_REFLECT(graphene::peerplays_sidechain::hive::public_key_type, (key_data)) +FC_REFLECT(graphene::peerplays_sidechain::hive::public_key_type::binary_key, (data)(check)) + +FC_REFLECT(graphene::peerplays_sidechain::hive::void_t, ) +FC_REFLECT_TYPENAME(graphene::peerplays_sidechain::hive::future_extensions) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp index 5b7ea6e9..6adfe944 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp @@ -37,6 +37,7 @@ public: boost::program_options::options_description &cfg) override; virtual void plugin_initialize(const boost::program_options::variables_map &options) override; virtual void plugin_startup() override; + virtual void plugin_shutdown() override; std::unique_ptr my; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp index 50dfd505..21526d05 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp @@ -4,7 +4,6 @@ #include -#include #include #include #include @@ -46,15 +45,19 @@ public: virtual bool process_withdrawal(const son_wallet_withdraw_object &swwo) = 0; virtual std::string process_sidechain_transaction(const sidechain_transaction_object &sto) = 0; virtual std::string send_sidechain_transaction(const sidechain_transaction_object &sto) = 0; - virtual int64_t settle_sidechain_transaction(const sidechain_transaction_object &sto) = 0; + virtual bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) = 0; protected: peerplays_sidechain_plugin &plugin; graphene::chain::database &database; sidechain_type sidechain; + bool debug_rpc_calls; + std::map private_keys; + void on_applied_block(const signed_block &b); + private: }; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp index eb218a4c..dd6ebb28 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp @@ -1,13 +1,14 @@ #pragma once -#include #include #include #include +#include + #include -#include +#include namespace graphene { namespace peerplays_sidechain { @@ -20,7 +21,7 @@ public: class bitcoin_rpc_client { public: - bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password); + bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password, bool _debug_rpc_calls); std::string addmultisigaddress(const uint32_t nrequired, const std::vector public_keys); std::string combinepsbt(const vector &psbts); @@ -50,7 +51,7 @@ public: //bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60); private: - fc::http::reply send_post_request(std::string body, bool show_log = false); + fc::http::reply send_post_request(std::string body, bool show_log); std::string ip; uint32_t rpc_port; @@ -58,6 +59,7 @@ private: std::string password; std::string wallet; std::string wallet_password; + bool debug_rpc_calls; fc::http::header authorization; }; @@ -68,7 +70,7 @@ class zmq_listener { public: zmq_listener(std::string _ip, uint32_t _zmq); - fc::signal event_received; + boost::signals2::signal event_received; private: void handle_zmq(); @@ -95,7 +97,7 @@ public: bool process_withdrawal(const son_wallet_withdraw_object &swwo); std::string process_sidechain_transaction(const sidechain_transaction_object &sto); std::string send_sidechain_transaction(const sidechain_transaction_object &sto); - int64_t settle_sidechain_transaction(const sidechain_transaction_object &sto); + bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount); private: std::string ip; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_hive.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_hive.hpp new file mode 100644 index 00000000..675c3cdd --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_hive.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include + +#include + +#include + +#include +#include +#include + +namespace graphene { namespace peerplays_sidechain { + +class hive_node_rpc_client : public rpc_client { +public: + hive_node_rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls); + + std::string account_history_api_get_transaction(std::string transaction_id); + std::string block_api_get_block(uint32_t block_number); + std::string condenser_api_get_accounts(std::vector accounts); + std::string condenser_api_get_config(); + std::string database_api_get_dynamic_global_properties(); + std::string database_api_get_version(); + std::string network_broadcast_api_broadcast_transaction(std::string htrx); + + std::string get_account(std::string account); + std::string get_account_memo_key(std::string account); + std::string get_chain_id(); + std::string get_head_block_id(); + std::string get_head_block_time(); + std::string get_is_test_net(); + std::string get_last_irreversible_block_num(); +}; + +class sidechain_net_handler_hive : public sidechain_net_handler { +public: + sidechain_net_handler_hive(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options); + virtual ~sidechain_net_handler_hive(); + + bool process_proposal(const proposal_object &po); + void process_primary_wallet(); + void process_sidechain_addresses(); + bool process_deposit(const son_wallet_deposit_object &swdo); + bool process_withdrawal(const son_wallet_withdraw_object &swwo); + std::string process_sidechain_transaction(const sidechain_transaction_object &sto); + std::string send_sidechain_transaction(const sidechain_transaction_object &sto); + bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount); + +private: + std::string node_ip; + uint32_t node_rpc_port; + std::string node_rpc_user; + std::string node_rpc_password; + hive_node_rpc_client *node_rpc_client; + + hive::chain_id_type chain_id; + hive::network network_type; + + uint64_t last_block_received; + fc::future _listener_task; + boost::signals2::signal event_received; + void schedule_hive_listener(); + void hive_listener_loop(); + void handle_event(const std::string &event_data); +}; + +}} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp index aa094d95..69eea1a9 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp @@ -4,8 +4,6 @@ #include -#include - namespace graphene { namespace peerplays_sidechain { class sidechain_net_handler_peerplays : public sidechain_net_handler { @@ -20,10 +18,9 @@ public: bool process_withdrawal(const son_wallet_withdraw_object &swwo); std::string process_sidechain_transaction(const sidechain_transaction_object &sto); std::string send_sidechain_transaction(const sidechain_transaction_object &sto); - int64_t settle_sidechain_transaction(const sidechain_transaction_object &sto); + bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount); private: - void on_applied_block(const signed_block &b); }; }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp index c2d40e14..a35c1933 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp @@ -29,6 +29,8 @@ private: peerplays_sidechain_plugin &plugin; graphene::chain::database &database; std::vector> net_handlers; + + void on_applied_block(const signed_block &b); }; }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index 7a57effb..02a046fc 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -29,6 +29,7 @@ public: boost::program_options::options_description &cfg); void plugin_initialize(const boost::program_options::variables_map &opt); void plugin_startup(); + void plugin_shutdown(); std::set &get_sons(); const son_id_type get_current_son_id(); @@ -68,8 +69,15 @@ private: bool config_ready_son; bool config_ready_bitcoin; + bool config_ready_ethereum; + bool config_ready_hive; bool config_ready_peerplays; + bool sidechain_enabled_bitcoin; + bool sidechain_enabled_ethereum; + bool sidechain_enabled_hive; + bool sidechain_enabled_peerplays; + son_id_type current_son_id; std::unique_ptr net_manager; @@ -88,7 +96,13 @@ peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidec plugin(_plugin), config_ready_son(false), config_ready_bitcoin(false), + config_ready_ethereum(false), + config_ready_hive(false), config_ready_peerplays(false), + sidechain_enabled_bitcoin(false), + sidechain_enabled_ethereum(false), + sidechain_enabled_hive(false), + sidechain_enabled_peerplays(false), current_son_id(son_id_type(std::numeric_limits().max())), net_manager(nullptr), first_block_skipped(false) { @@ -125,6 +139,12 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options( cli.add_options()("son-ids", bpo::value(), ("IDs of multiple SONs controlled by this node (e.g. [" + son_id_example + ", " + son_id_example2 + "], quotes are required)").c_str()); cli.add_options()("peerplays-private-key", bpo::value>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR(std::make_pair(chain::public_key_type(default_priv_key.get_public_key()), graphene::utilities::key_to_wif(default_priv_key))), "Tuple of [PublicKey, WIF private key] (may specify multiple times)"); + + cli.add_options()("sidechain-retry-threshold", bpo::value()->default_value(150), "Sidechain retry throttling threshold"); + + cli.add_options()("debug-rpc-calls", bpo::value()->default_value(false), "Outputs RPC calls to console"); + + cli.add_options()("bitcoin-sidechain-enabled", bpo::value()->default_value(false), "Bitcoin sidechain handler enabled"); cli.add_options()("bitcoin-node-ip", bpo::value()->default_value("127.0.0.1"), "IP address of Bitcoin node"); cli.add_options()("bitcoin-node-zmq-port", bpo::value()->default_value(11111), "ZMQ port of Bitcoin node"); cli.add_options()("bitcoin-node-rpc-port", bpo::value()->default_value(8332), "RPC port of Bitcoin node"); @@ -134,7 +154,15 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options( cli.add_options()("bitcoin-wallet-password", bpo::value(), "Bitcoin wallet password"); cli.add_options()("bitcoin-private-key", bpo::value>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR(std::make_pair("02d0f137e717fb3aab7aff99904001d49a0a636c5e1342f8927a4ba2eaee8e9772", "cVN31uC9sTEr392DLVUEjrtMgLA8Yb3fpYmTRj7bomTm6nn2ANPr")), "Tuple of [Bitcoin public key, Bitcoin private key] (may specify multiple times)"); - cli.add_options()("sidechain-retry-threshold", bpo::value()->default_value(150), "Sidechain retry throttling threshold"); + + cli.add_options()("hive-sidechain-enabled", bpo::value()->default_value(false), "Hive sidechain handler enabled"); + cli.add_options()("hive-node-ip", bpo::value()->default_value("127.0.0.1"), "Hive node IP address"); + cli.add_options()("hive-node-rpc-port", bpo::value()->default_value(28090), "Hive node RPC port"); + cli.add_options()("hive-node-rpc-user", bpo::value(), "Hive node RPC user"); + cli.add_options()("hive-node-rpc-password", bpo::value(), "Hive node RPC password"); + cli.add_options()("hive-private-key", bpo::value>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR(std::make_pair("TST6LLegbAgLAy28EHrffBVuANFWcFgmqRMW13wBmTExqFE9SCkg4", "5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n")), + "Tuple of [Hive public key, Hive private key] (may specify multiple times)"); + cfg.add(cli); } @@ -143,8 +171,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 @@ -172,7 +202,9 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt } config_ready_son = config_ready_son && !private_keys.empty(); } - retries_threshold = options.at("sidechain-retry-threshold").as(); + if (options.count("sidechain-retry-threshold")) { + retries_threshold = options.at("sidechain-retry-threshold").as(); + } ilog("sidechain-retry-threshold: ${sidechain-retry-threshold}", ("sidechain-retry-threshold", retries_threshold)); } if (!config_ready_son) { @@ -180,27 +212,47 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt throw; } + sidechain_enabled_bitcoin = options.at("bitcoin-sidechain-enabled").as(); config_ready_bitcoin = options.count("bitcoin-node-ip") && options.count("bitcoin-node-zmq-port") && options.count("bitcoin-node-rpc-port") && options.count("bitcoin-node-rpc-user") && options.count("bitcoin-node-rpc-password") && - /*options.count( "bitcoin-wallet" ) && options.count( "bitcoin-wallet-password" ) &&*/ + /*options.count("bitcoin-wallet") && options.count("bitcoin-wallet-password") &&*/ options.count("bitcoin-private-key"); if (!config_ready_bitcoin) { wlog("Haven't set up Bitcoin sidechain parameters"); } - //config_ready_ethereum = options.count( "ethereum-node-ip" ) && - // options.count( "ethereum-address" ) && options.count( "ethereum-public-key" ) && options.count( "ethereum-private-key" ); + //sidechain_enabled_ethereum = options.at("ethereum-sidechain-enabled").as(); + //config_ready_ethereum = options.count("ethereum-node-ip") && + // options.count("ethereum-address") && + // options.count("ethereum-public-key") && options.count("ethereum-private-key"); //if (!config_ready_ethereum) { // wlog("Haven't set up Ethereum sidechain parameters"); //} + sidechain_enabled_hive = options.at("hive-sidechain-enabled").as(); + config_ready_hive = options.count("hive-node-ip") && + options.count("hive-node-rpc-port") && + /*options.count("hive-node-rpc-user") && options.count("hive-node-rpc-password") &&*/ + options.count("hive-private-key"); + if (!config_ready_hive) { + wlog("Haven't set up Hive sidechain parameters"); + } + +#ifdef ENABLE_PEERPLAYS_ASSET_DEPOSITS + sidechain_enabled_peerplays = true; //options.at("peerplays-sidechain-enabled").as(); +#else + sidechain_enabled_peerplays = false; +#endif config_ready_peerplays = true; if (!config_ready_peerplays) { wlog("Haven't set up Peerplays sidechain parameters"); } - if (!(config_ready_bitcoin /*&& config_ready_ethereum*/ && config_ready_peerplays)) { + if (!(config_ready_bitcoin && + /*config_ready_ethereum &&*/ + config_ready_hive && + config_ready_peerplays)) { wlog("Haven't set up any sidechain parameters"); throw; } @@ -218,17 +270,22 @@ void peerplays_sidechain_plugin_impl::plugin_startup() { net_manager = std::unique_ptr(new sidechain_net_manager(plugin)); - if (config_ready_bitcoin) { + if (sidechain_enabled_bitcoin && config_ready_bitcoin) { net_manager->create_handler(sidechain_type::bitcoin, options); ilog("Bitcoin sidechain handler running"); } - //if (config_ready_ethereum) { + //if (sidechain_enabled_ethereum && config_ready_ethereum) { // net_manager->create_handler(sidechain_type::ethereum, options); // ilog("Ethereum sidechain handler running"); //} - if (config_ready_peerplays) { + if (sidechain_enabled_hive && config_ready_hive) { + net_manager->create_handler(sidechain_type::hive, options); + ilog("Hive sidechain handler running"); + } + + if (sidechain_enabled_peerplays && config_ready_peerplays) { net_manager->create_handler(sidechain_type::peerplays, options); ilog("Peerplays sidechain handler running"); } @@ -238,6 +295,9 @@ void peerplays_sidechain_plugin_impl::plugin_startup() { }); } +void peerplays_sidechain_plugin_impl::plugin_shutdown() { +} + std::set &peerplays_sidechain_plugin_impl::get_sons() { return sons; } @@ -388,9 +448,15 @@ void peerplays_sidechain_plugin_impl::son_processing() { return; } + //fc::time_point now_fine = fc::time_point::now(); + //fc::time_point_sec now = now_fine + fc::microseconds(500000); + //if (plugin.database().get_slot_time(1) < now) { + // return; // Not synced + //} + fc::time_point now_fine = fc::time_point::now(); - fc::time_point_sec now = now_fine + fc::microseconds(500000); - if (plugin.database().get_slot_time(1) < now) { + fc::time_point_sec now = now_fine - fc::milliseconds(3000); + if (plugin.database().head_block_time() < now) { return; // Not synced } @@ -684,6 +750,12 @@ void peerplays_sidechain_plugin::plugin_startup() { ilog("peerplays sidechain plugin: plugin_startup() end"); } +void peerplays_sidechain_plugin::plugin_shutdown() { + ilog("peerplays sidechain plugin: plugin_shutdown() begin"); + my->plugin_shutdown(); + ilog("peerplays sidechain plugin: plugin_shutdown() end"); +} + std::set &peerplays_sidechain_plugin::get_sons() { return my->get_sons(); } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp index d025c178..06a76502 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -1,14 +1,21 @@ #include +#include + #include #include #include +#include namespace graphene { namespace peerplays_sidechain { sidechain_net_handler::sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) : plugin(_plugin), database(_plugin.database()) { + + database.applied_block.connect([&](const signed_block &b) { + on_applied_block(b); + }); } sidechain_net_handler::~sidechain_net_handler() { @@ -161,21 +168,25 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ const chain::global_property_object &gpo = database.get_global_properties(); - asset_id_type btc_asset_id = database.get_global_properties().parameters.btc_asset(); - std::string btc_asset_id_str = fc::to_string(btc_asset_id.space_id) + "." + - fc::to_string(btc_asset_id.type_id) + "." + - fc::to_string((uint64_t)btc_asset_id.instance); - + bool enable_peerplays_asset_deposits = false; #ifdef ENABLE_PEERPLAYS_ASSET_DEPOSITS - // Accepts BTC and peerplays asset deposits - bool deposit_condition = ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare(btc_asset_id_str) != 0)); - bool withdraw_condition = ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare(btc_asset_id_str) == 0)); -#else - // Accepts BTC deposits only - bool deposit_condition = ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare("BTC") == 0)); - bool withdraw_condition = ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare(btc_asset_id_str) == 0)); + //enable_peerplays_asset_deposits = (sed.sidechain == sidechain_type::peerplays) && + // (sed.sidechain_currency.compare("BTC") != 0) && + // (sed.sidechain_currency.compare("HBD") != 0) && + // (sed.sidechain_currency.compare("HIVE") != 0); #endif + bool deposit_condition = (sed.peerplays_to == gpo.parameters.son_account()) && + (((sed.sidechain == sidechain_type::bitcoin) && (sed.sidechain_currency.compare("BTC") == 0)) || + ((sed.sidechain == sidechain_type::hive) && (sed.sidechain_currency.compare("HBD") == 0)) || + ((sed.sidechain == sidechain_type::hive) && (sed.sidechain_currency.compare("HIVE") == 0)) || + enable_peerplays_asset_deposits); + + bool withdraw_condition = (sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain == sidechain_type::peerplays) && + ((sed.sidechain_currency == object_id_to_string(gpo.parameters.btc_asset())) || + (sed.sidechain_currency == object_id_to_string(gpo.parameters.hbd_asset())) || + (sed.sidechain_currency == object_id_to_string(gpo.parameters.hive_asset()))); + // Deposit request if (deposit_condition) { @@ -214,11 +225,32 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ // Withdrawal request if (withdraw_condition) { - // BTC Payout only (for now) + std::string withdraw_address = ""; const auto &sidechain_addresses_idx = database.get_index_type().indices().get(); - const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain_type::bitcoin, time_point_sec::maximum())); - if (addr_itr == sidechain_addresses_idx.end()) + const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain, time_point_sec::maximum())); + if (addr_itr != sidechain_addresses_idx.end()) { + withdraw_address = addr_itr->withdraw_address; + } else { + withdraw_address = sed.sidechain_from; + } + + std::string withdraw_currency = ""; + price withdraw_currency_price = {}; + if (sed.sidechain_currency == object_id_to_string(gpo.parameters.btc_asset())) { + withdraw_currency = "BTC"; + withdraw_currency_price = database.get(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate; + } + if (sed.sidechain_currency == object_id_to_string(gpo.parameters.hbd_asset())) { + withdraw_currency = "HBD"; + withdraw_currency_price = database.get(database.get_global_properties().parameters.hbd_asset()).options.core_exchange_rate; + } + if (sed.sidechain_currency == object_id_to_string(gpo.parameters.hive_asset())) { + withdraw_currency = "HIVE"; + withdraw_currency_price = database.get(database.get_global_properties().parameters.hive_asset()).options.core_exchange_rate; + } + if (withdraw_currency.empty()) { return; + } for (son_id_type son_id : plugin.get_sons()) { if (plugin.is_active_son(son_id)) { @@ -233,12 +265,10 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ op.peerplays_transaction_id = sed.sidechain_transaction_id; op.peerplays_from = sed.peerplays_from; op.peerplays_asset = sed.peerplays_asset; - // BTC payout only (for now) - op.withdraw_sidechain = sidechain_type::bitcoin; - op.withdraw_address = addr_itr->withdraw_address; - op.withdraw_currency = "BTC"; - price btc_price = database.get(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate; - op.withdraw_amount = sed.peerplays_asset.amount * btc_price.quote.amount / btc_price.base.amount; + op.withdraw_sidechain = sidechain; + op.withdraw_address = withdraw_address; + op.withdraw_currency = withdraw_currency; + op.withdraw_amount = sed.peerplays_asset.amount * withdraw_currency_price.quote.amount / withdraw_currency_price.base.amount; signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), op); try { @@ -389,9 +419,13 @@ void sidechain_net_handler::process_deposits() { } //Ignore the deposits which are not valid anymore, considered refunds. const auto &sidechain_addresses_idx = database.get_index_type().indices().get(); - const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, swdo.sidechain_to, time_point_sec::maximum())); + const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, swdo.sidechain_from, time_point_sec::maximum())); if (addr_itr == sidechain_addresses_idx.end()) { - return; + const auto &account_idx = database.get_index_type().indices().get(); + const auto &account_itr = account_idx.find(swdo.sidechain_from); + if (account_itr == account_idx.end()) { + return; + } } ilog("Deposit to process: ${swdo}", ("swdo", swdo)); @@ -532,9 +566,10 @@ void sidechain_net_handler::settle_sidechain_transactions() { ilog("Sidechain transaction to settle: ${sto}", ("sto", sto.id)); - int64_t settle_amount = settle_sidechain_transaction(sto); + asset settle_amount; + bool settle_sidechain_result = settle_sidechain_transaction(sto, settle_amount); - if (settle_amount < 0) { + if (settle_sidechain_result == false) { wlog("Sidechain transaction not settled: ${sto}", ("sto", sto.id)); return; } @@ -551,12 +586,12 @@ void sidechain_net_handler::settle_sidechain_transactions() { sts_op.sidechain_transaction_id = sto.id; proposal_op.proposed_ops.emplace_back(sts_op); - if (settle_amount != 0) { + if (settle_amount.amount != 0) { if (sto.object_id.is()) { asset_issue_operation ai_op; ai_op.fee = asset(2001000); ai_op.issuer = gpo.parameters.son_account(); - ai_op.asset_to_issue = asset(settle_amount, database.get_global_properties().parameters.btc_asset()); + ai_op.asset_to_issue = settle_amount; ai_op.issue_to_account = database.get(sto.object_id).peerplays_from; proposal_op.proposed_ops.emplace_back(ai_op); } @@ -565,7 +600,7 @@ void sidechain_net_handler::settle_sidechain_transactions() { asset_reserve_operation ar_op; ar_op.fee = asset(2001000); ar_op.payer = gpo.parameters.son_account(); - ar_op.amount_to_reserve = asset(settle_amount, database.get_global_properties().parameters.btc_asset()); + ar_op.amount_to_reserve = settle_amount; proposal_op.proposed_ops.emplace_back(ar_op); } } @@ -583,4 +618,63 @@ void sidechain_net_handler::settle_sidechain_transactions() { }); } +void sidechain_net_handler::on_applied_block(const signed_block &b) { + + const chain::global_property_object &gpo = plugin.database().get_global_properties(); + + for (const auto &trx : b.transactions) { + size_t operation_index = -1; + for (auto op : trx.operations) { + operation_index = operation_index + 1; + if (op.which() == operation::tag::value) { + transfer_operation transfer_op = op.get(); + + if (transfer_op.to != gpo.parameters.son_account()) { + continue; + } + + bool is_tracked_asset = + ((sidechain == sidechain_type::bitcoin) && (transfer_op.amount.asset_id == gpo.parameters.btc_asset())) || + ((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hbd_asset())) || + ((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hive_asset())); + + if (!is_tracked_asset) { + continue; + } + + std::string sidechain_from = object_id_to_string(transfer_op.from); + std::string memo = ""; + if (transfer_op.memo) { + memo = transfer_op.memo->get_message(fc::ecc::private_key(), public_key_type()); + boost::trim(memo); + if (!memo.empty()) { + sidechain_from = memo; + } + } + + std::stringstream ss; + ss << "peerplays" + << "-" << trx.id().str() << "-" << operation_index; + std::string sidechain_uid = ss.str(); + + sidechain_event_data sed; + sed.timestamp = database.head_block_time(); + sed.block_num = database.head_block_num(); + sed.sidechain = sidechain_type::peerplays; + sed.sidechain_uid = sidechain_uid; + sed.sidechain_transaction_id = trx.id().str(); + sed.sidechain_from = sidechain_from; + sed.sidechain_to = object_id_to_string(transfer_op.to); + sed.sidechain_currency = object_id_to_string(transfer_op.amount.asset_id); + sed.sidechain_amount = transfer_op.amount.amount; + sed.peerplays_from = transfer_op.from; + sed.peerplays_to = transfer_op.to; + price asset_price = database.get(transfer_op.amount.asset_id).options.core_exchange_rate; + sed.peerplays_asset = asset(transfer_op.amount.amount * asset_price.base.amount / asset_price.quote.amount); + sidechain_event_data_received(sed); + } + } + } +} + }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 7c0b0074..ca4e9149 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -26,13 +26,14 @@ namespace graphene { namespace peerplays_sidechain { // ============================================================================= -bitcoin_rpc_client::bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password) : +bitcoin_rpc_client::bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password, bool _debug_rpc_calls) : ip(_ip), rpc_port(_rpc), user(_user), password(_password), wallet(_wallet), - wallet_password(_wallet_password) { + wallet_password(_wallet_password), + debug_rpc_calls(_debug_rpc_calls) { authorization.key = "Authorization"; authorization.val = "Basic " + fc::base64_encode(user + ":" + password); } @@ -51,7 +52,7 @@ std::string bitcoin_rpc_client::addmultisigaddress(const uint32_t nrequired, con params = params + pubkeys + std::string("]"); body = body + params + std::string(", null, \"bech32\"] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -83,7 +84,7 @@ std::string bitcoin_rpc_client::combinepsbt(const vector &psbts) { params = params + std::string("\"") + psbt + std::string("\""); } body = body + params + std::string("]] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -120,7 +121,7 @@ std::string bitcoin_rpc_client::createmultisig(const uint32_t nrequired, const s params = params + pubkeys + std::string("]"); body = body + params + std::string(", \"p2sh-segwit\" ] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -162,7 +163,7 @@ std::string bitcoin_rpc_client::createpsbt(const std::vector &ins, co } body += std::string("]] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -206,7 +207,7 @@ std::string bitcoin_rpc_client::createrawtransaction(const std::vector bitcoin_rpc_client::listunspent(const uint32_t minconf, c "\"listunspent\", \"params\": [" + std::to_string(minconf) + "," + std::to_string(maxconf) + "] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); std::vector result; @@ -617,7 +618,7 @@ std::vector bitcoin_rpc_client::listunspent_by_address_and_amount(con body += std::to_string(minimum_amount); body += std::string("} ] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); std::vector result; if (reply.body.empty()) { @@ -652,7 +653,7 @@ std::string bitcoin_rpc_client::loadwallet(const std::string &filename) { "\"loadwallet\", \"params\": [\"" + filename + "\"] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -680,7 +681,7 @@ std::string bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) { "\"method\": \"sendrawtransaction\", \"params\": [") + std::string("\"") + tx_hex + std::string("\"") + std::string("] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -707,7 +708,7 @@ std::string bitcoin_rpc_client::signrawtransactionwithwallet(const std::string & std::string params = "\"" + tx_hash + "\""; body = body + params + std::string("]}"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -733,7 +734,7 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) { "\"unloadwallet\", \"params\": [\"" + filename + "\"] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -760,7 +761,7 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) { // std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletlock\", \"method\": " // "\"walletlock\", \"params\": [] }"); // -// const auto reply = send_post_request(body); +// const auto reply = send_post_request(body, debug_rpc_calls); // // if (reply.body.empty()) { // wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -788,7 +789,7 @@ std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) { "\"walletprocesspsbt\", \"params\": [\"" + tx_psbt + "\"] }"); - const auto reply = send_post_request(body); + const auto reply = send_post_request(body, debug_rpc_calls); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -814,7 +815,7 @@ std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) { // "\"walletpassphrase\", \"params\": [\"" + // passphrase + "\", " + std::to_string(timeout) + "] }"); // -// const auto reply = send_post_request(body); +// const auto reply = send_post_request(body, debug_rpc_calls); // // if (reply.body.empty()) { // wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -911,6 +912,10 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain sidechain_net_handler(_plugin, options) { sidechain = sidechain_type::bitcoin; + if (options.count("debug-rpc-calls")) { + debug_rpc_calls = options.at("debug-rpc-calls").as(); + } + ip = options.at("bitcoin-node-ip").as(); zmq_port = options.at("bitcoin-node-zmq-port").as(); rpc_port = options.at("bitcoin-node-rpc-port").as(); @@ -945,7 +950,7 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain FC_ASSERT(false); } - bitcoin_client = std::unique_ptr(new bitcoin_rpc_client(ip, rpc_port, rpc_user, rpc_password, wallet, wallet_password)); + bitcoin_client = std::unique_ptr(new bitcoin_rpc_client(ip, rpc_port, rpc_user, rpc_password, wallet, wallet_password, debug_rpc_calls)); if (!wallet.empty()) { bitcoin_client->loadwallet(wallet); } @@ -989,7 +994,7 @@ sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() { bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) { - ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id())); + //ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id())); bool should_approve = false; @@ -1094,7 +1099,7 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) if (swdo != idx.end()) { std::string swdo_txid = swdo->sidechain_transaction_id; - std::string swdo_address = swdo->sidechain_to; + std::string swdo_address = swdo->sidechain_from; uint64_t swdo_amount = swdo->sidechain_amount.value; uint64_t swdo_vout = std::stoll(swdo->sidechain_uid.substr(swdo->sidechain_uid.find_last_of("-") + 1)); @@ -1108,8 +1113,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"); @@ -1354,6 +1359,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))); @@ -1379,13 +1385,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; + elog("Sending transaction for sidechain address update operation failed with exception ${e}", ("e", e.what())); + retval = false; } } } + return retval; }); } @@ -1485,16 +1492,15 @@ std::string sidechain_net_handler_bitcoin::send_sidechain_transaction(const side return send_transaction(sto); } -int64_t sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain_transaction_object &sto) { +bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) { if (sto.object_id.is()) { - return 0; + settle_amount = asset(0, database.get_global_properties().parameters.btc_asset()); + return true; } - int64_t settle_amount = -1; - if (sto.sidechain_transaction.empty()) { - return settle_amount; + return false; } std::string tx_str = bitcoin_client->getrawtransaction(sto.sidechain_transaction, true); @@ -1503,7 +1509,7 @@ int64_t sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidech boost::property_tree::read_json(tx_ss, tx_json); if ((tx_json.count("error")) && (!tx_json.get_child("error").empty())) { - return settle_amount; + return false; } const chain::global_property_object &gpo = database.get_global_properties(); @@ -1534,15 +1540,17 @@ int64_t sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidech } } } - settle_amount = tx_amount; + settle_amount = asset(tx_amount, database.get_global_properties().parameters.btc_asset()); + return true; } if (sto.object_id.is()) { auto swwo = database.get(sto.object_id); - settle_amount = swwo.withdraw_amount.value; + settle_amount = asset(swwo.withdraw_amount, database.get_global_properties().parameters.btc_asset()); + return true; } } - return settle_amount; + return false; } std::string sidechain_net_handler_bitcoin::create_primary_wallet_address(const std::vector &son_pubkeys) { @@ -1568,7 +1576,17 @@ std::string sidechain_net_handler_bitcoin::create_primary_wallet_address(const s std::string sidechain_net_handler_bitcoin::create_primary_wallet_transaction(const son_wallet_object &prev_swo, std::string new_sw_address) { - std::stringstream prev_sw_ss(prev_swo.addresses.find(sidechain_type::bitcoin)->second); + const auto &address_data = prev_swo.addresses.find(sidechain_type::bitcoin); + if (address_data == prev_swo.addresses.end()) { + return ""; + } + + std::string s = address_data->second; + if (s.empty()) { + return ""; + } + + std::stringstream prev_sw_ss(s); boost::property_tree::ptree prev_sw_pt; boost::property_tree::read_json(prev_sw_ss, prev_sw_pt); std::string prev_pw_address = prev_sw_pt.get("address"); @@ -1613,7 +1631,7 @@ std::string sidechain_net_handler_bitcoin::create_deposit_transaction(const son_ return ""; } //Get redeem script for deposit address - std::string redeem_script = get_redeemscript_for_userdeposit(swdo.sidechain_to); + std::string redeem_script = get_redeemscript_for_userdeposit(swdo.sidechain_from); std::string pw_address_json = obj->addresses.find(sidechain_type::bitcoin)->second; std::stringstream ss(pw_address_json); @@ -1663,11 +1681,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) { @@ -1805,8 +1823,8 @@ void sidechain_net_handler_bitcoin::handle_event(const std::string &event_data) sed.sidechain = addr_itr->sidechain; sed.sidechain_uid = sidechain_uid; sed.sidechain_transaction_id = v.out.hash_tx; - sed.sidechain_from = ""; - sed.sidechain_to = v.address; + sed.sidechain_from = v.address; + sed.sidechain_to = ""; sed.sidechain_currency = "BTC"; sed.sidechain_amount = v.out.amount; sed.peerplays_from = addr_itr->sidechain_address_account; diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp new file mode 100644 index 00000000..3b3701dd --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp @@ -0,0 +1,971 @@ +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace graphene { namespace peerplays_sidechain { + +std::string resolve_host_addr(const std::string &host_name) { + using namespace boost::asio; + io_service service; + ip::tcp::resolver resolver(service); + auto query = ip::tcp::resolver::query(host_name, std::string()); + auto iter = resolver.resolve(query); + auto endpoint = *iter; + auto addr = ((ip::tcp::endpoint)endpoint).address(); + return addr.to_string(); +} + +std::string strip_proto_name(const std::string &url, std::string *schema) { + auto index = url.find("://"); + if (index == std::string::npos) { + if (schema) + schema->clear(); + return url; + } + if (schema) + schema->assign(&url[0], &url[index + 3]); + return url.substr(index + 3); +} + +}} // namespace graphene::peerplays_sidechain + +namespace graphene { namespace peerplays_sidechain { + +hive_node_rpc_client::hive_node_rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls) : + rpc_client(_ip, _port, _user, _password, _debug_rpc_calls) { +} + +std::string hive_node_rpc_client::account_history_api_get_transaction(std::string transaction_id) { + std::string params = "{ \"id\": \"" + transaction_id + "\" }"; + return send_post_request("account_history_api.get_transaction", params, debug_rpc_calls); +} + +std::string hive_node_rpc_client::block_api_get_block(uint32_t block_number) { + std::string params = "{ \"block_num\": " + std::to_string(block_number) + " }"; + return send_post_request("block_api.get_block", params, debug_rpc_calls); +} + +std::string hive_node_rpc_client::condenser_api_get_accounts(std::vector accounts) { + std::string params = ""; + for (auto account : accounts) { + if (!params.empty()) { + params = params + ","; + } + params = "\"" + account + "\""; + } + params = "[[" + params + "]]"; + return send_post_request("condenser_api.get_accounts", params, debug_rpc_calls); +} + +std::string hive_node_rpc_client::condenser_api_get_config() { + std::string params = "[]"; + return send_post_request("condenser_api.get_config", params, debug_rpc_calls); +} + +std::string hive_node_rpc_client::database_api_get_dynamic_global_properties() { + return send_post_request("database_api.get_dynamic_global_properties", "", debug_rpc_calls); +} + +std::string hive_node_rpc_client::database_api_get_version() { + return send_post_request("database_api.get_version", "", debug_rpc_calls); +} + +std::string hive_node_rpc_client::network_broadcast_api_broadcast_transaction(std::string htrx) { + std::string params = "{ \"trx\": " + htrx + ", \"max_block_age\": -1 }"; + return send_post_request("network_broadcast_api.broadcast_transaction", params, debug_rpc_calls); +} + +std::string hive_node_rpc_client::get_account(std::string account) { + std::vector accounts; + accounts.push_back(account); + std::string reply_str = condenser_api_get_accounts(accounts); + return retrieve_array_value_from_reply(reply_str, "", 0); +} + +std::string hive_node_rpc_client::get_account_memo_key(std::string account) { + std::string reply_str = get_account(account); + reply_str = "{\"result\":" + reply_str + "}"; + return retrieve_value_from_reply(reply_str, "memo_key"); +} + +std::string hive_node_rpc_client::get_chain_id() { + std::string reply_str = database_api_get_version(); + return retrieve_value_from_reply(reply_str, "chain_id"); +} + +std::string hive_node_rpc_client::get_head_block_id() { + std::string reply_str = database_api_get_dynamic_global_properties(); + return retrieve_value_from_reply(reply_str, "head_block_id"); +} + +std::string hive_node_rpc_client::get_head_block_time() { + std::string reply_str = database_api_get_dynamic_global_properties(); + return retrieve_value_from_reply(reply_str, "time"); +} + +std::string hive_node_rpc_client::get_is_test_net() { + std::string reply_str = condenser_api_get_config(); + return retrieve_value_from_reply(reply_str, "IS_TEST_NET"); +} + +std::string hive_node_rpc_client::get_last_irreversible_block_num() { + std::string reply_str = database_api_get_dynamic_global_properties(); + return retrieve_value_from_reply(reply_str, "last_irreversible_block_num"); +} + +sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) : + sidechain_net_handler(_plugin, options) { + sidechain = sidechain_type::hive; + + if (options.count("debug-rpc-calls")) { + debug_rpc_calls = options.at("debug-rpc-calls").as(); + } + + node_ip = options.at("hive-node-ip").as(); + node_rpc_port = options.at("hive-node-rpc-port").as(); + if (options.count("hive-node-rpc-user")) { + node_rpc_user = options.at("hive-node-rpc-user").as(); + } else { + node_rpc_user = ""; + } + if (options.count("hive-node-rpc-password")) { + node_rpc_password = options.at("hive-node-rpc-password").as(); + } else { + node_rpc_password = ""; + } + + if (options.count("hive-private-key")) { + const std::vector pub_priv_keys = options["hive-private-key"].as>(); + for (const std::string &itr_key_pair : pub_priv_keys) { + auto key_pair = graphene::app::dejsonify>(itr_key_pair, 5); + ilog("Hive Public Key: ${public}", ("public", key_pair.first)); + if (!key_pair.first.length() || !key_pair.second.length()) { + FC_THROW("Invalid public private key pair."); + } + private_keys[key_pair.first] = key_pair.second; + } + } + + node_rpc_client = new hive_node_rpc_client(node_ip, node_rpc_port, node_rpc_user, node_rpc_password, debug_rpc_calls); + + std::string chain_id_str = node_rpc_client->get_chain_id(); + if (chain_id_str.empty()) { + elog("No Hive node running at ${ip} or wrong rpc port: ${port}", ("ip", node_ip)("port", node_rpc_port)); + FC_ASSERT(false); + } + chain_id = chain_id_type(chain_id_str); + + std::string is_test_net = node_rpc_client->get_is_test_net(); + network_type = is_test_net.compare("true") == 0 ? hive::network::testnet : hive::network::mainnet; + if (network_type == hive::network::mainnet) { + ilog("Running on Hive mainnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str)); + hive::asset::hbd_symbol_ser = HBD_SYMBOL_SER; + hive::asset::hive_symbol_ser = HIVE_SYMBOL_SER; + hive::public_key_type::prefix = KEY_PREFIX_STM; + } else { + ilog("Running on Hive testnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str)); + hive::asset::hbd_symbol_ser = TBD_SYMBOL_SER; + hive::asset::hive_symbol_ser = TESTS_SYMBOL_SER; + hive::public_key_type::prefix = KEY_PREFIX_TST; + } + + last_block_received = 0; + schedule_hive_listener(); + event_received.connect([this](const std::string &event_data) { + std::thread(&sidechain_net_handler_hive::handle_event, this, event_data).detach(); + }); +} + +sidechain_net_handler_hive::~sidechain_net_handler_hive() { +} + +bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) { + //ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id())); + + bool should_approve = false; + + const chain::global_property_object &gpo = database.get_global_properties(); + + int32_t op_idx_0 = -1; + chain::operation op_obj_idx_0; + + if (po.proposed_transaction.operations.size() >= 1) { + op_idx_0 = po.proposed_transaction.operations[0].which(); + op_obj_idx_0 = po.proposed_transaction.operations[0]; + } + + 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(); + op_obj_idx_1 = po.proposed_transaction.operations[1]; + } + + switch (op_idx_0) { + + case chain::operation::tag::value: { + bool address_ok = false; + bool transaction_ok = false; + son_wallet_id_type swo_id = op_obj_idx_0.get().son_wallet_id; + const auto &idx = database.get_index_type().indices().get(); + const auto swo = idx.find(swo_id); + if (swo != idx.end()) { + + auto active_sons = gpo.active_sons; + vector wallet_sons = swo->sons; + + bool son_sets_equal = (active_sons.size() == wallet_sons.size()); + + if (son_sets_equal) { + for (size_t i = 0; i < active_sons.size(); i++) { + son_sets_equal = son_sets_equal && active_sons.at(i) == wallet_sons.at(i); + } + } + + if (son_sets_equal) { + address_ok = (op_obj_idx_0.get().address == "son-account"); + } + + if (po.proposed_transaction.operations.size() >= 2) { + object_id_type object_id = op_obj_idx_1.get().object_id; + std::string op_tx_str = op_obj_idx_1.get().transaction; + + const auto &st_idx = database.get_index_type().indices().get(); + const auto st = st_idx.find(object_id); + if (st == st_idx.end()) { + + std::string tx_str = ""; + + if (object_id.is()) { + const auto &idx = database.get_index_type().indices().get(); + const auto swo = idx.find(object_id); + if (swo != idx.end()) { + + std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str)); + hive::signed_transaction op_trx; + fc::raw::unpack(ss_trx, op_trx, 1000); + + fc::flat_map account_auths; + uint32_t total_weight = 0; + for (const auto &wallet_son : wallet_sons) { + total_weight = total_weight + wallet_son.weight; + account_auths[wallet_son.sidechain_public_keys.at(sidechain)] = wallet_son.weight; + } + + std::string memo_key = node_rpc_client->get_account_memo_key("son-account"); + + hive::authority active; + active.weight_threshold = total_weight * 2 / 3 + 1; + active.account_auths = account_auths; + + hive::account_update_operation auo; + auo.account = "son-account"; + auo.active = active; + auo.memo_key = op_trx.operations[0].get().memo_key; + + hive::signed_transaction htrx; + htrx.ref_block_num = op_trx.ref_block_num; + htrx.ref_block_prefix = op_trx.ref_block_prefix; + htrx.set_expiration(op_trx.expiration); + + htrx.operations.push_back(auo); + + std::stringstream ss; + fc::raw::pack(ss, htrx, 1000); + tx_str = boost::algorithm::hex(ss.str()); + } + } + + transaction_ok = (op_tx_str == tx_str); + } + } else { + transaction_ok = true; + } + } + + should_approve = address_ok && + transaction_ok; + break; + } + + case chain::operation::tag::value: { + bool process_ok = false; + son_wallet_deposit_id_type swdo_id = op_obj_idx_0.get().son_wallet_deposit_id; + const auto &idx = database.get_index_type().indices().get(); + const auto swdo = idx.find(swdo_id); + if (swdo != idx.end()) { + + std::string swdo_txid = swdo->sidechain_transaction_id; + std::string swdo_sidechain_from = swdo->sidechain_from; + std::string swdo_sidechain_currency = swdo->sidechain_currency; + uint64_t swdo_sidechain_amount = swdo->sidechain_amount.value; + uint64_t swdo_op_idx = std::stoll(swdo->sidechain_uid.substr(swdo->sidechain_uid.find_last_of("-"))); + + std::string tx_str = node_rpc_client->account_history_api_get_transaction(swdo_txid); + if (tx_str != "") { + + std::stringstream ss_tx(tx_str); + boost::property_tree::ptree tx; + boost::property_tree::read_json(ss_tx, tx); + + uint64_t op_idx = -1; + for (const auto &ops : tx.get_child("result.operations")) { + const auto &op = ops.second; + op_idx = op_idx + 1; + if (op_idx == swdo_op_idx) { + std::string operation_type = op.get("type"); + + if (operation_type == "transfer_operation") { + const auto &op_value = op.get_child("value"); + + std::string sidechain_from = op_value.get("from"); + + const auto &amount_child = op_value.get_child("amount"); + + uint64_t amount = amount_child.get("amount"); + std::string nai = amount_child.get("nai"); + std::string sidechain_currency = ""; + if ((nai == "@@000000013" /*?? HBD*/) || (nai == "@@000000013" /*TBD*/)) { + sidechain_currency = "HBD"; + } + if ((nai == "@@000000021") /*?? HIVE*/ || (nai == "@@000000021" /*TESTS*/)) { + sidechain_currency = "HIVE"; + } + + std::string memo = op_value.get("memo"); + boost::trim(memo); + if (!memo.empty()) { + sidechain_from = memo; + } + + process_ok = (swdo_sidechain_from == sidechain_from) && + (swdo_sidechain_currency == sidechain_currency) && + (swdo_sidechain_amount == amount); + } + } + } + } + } + should_approve = process_ok; + break; + } + + case chain::operation::tag::value: { + bool process_ok = false; + bool transaction_ok = false; + son_wallet_withdraw_id_type swwo_id = op_obj_idx_0.get().son_wallet_withdraw_id; + const auto &idx = database.get_index_type().indices().get(); + const auto swwo = idx.find(swwo_id); + if (swwo != idx.end()) { + + uint32_t swwo_block_num = swwo->block_num; + std::string swwo_peerplays_transaction_id = swwo->peerplays_transaction_id; + uint32_t swwo_op_idx = std::stoll(swwo->peerplays_uid.substr(swwo->peerplays_uid.find_last_of("-") + 1)); + + const auto &block = database.fetch_block_by_number(swwo_block_num); + + for (const auto &tx : block->transactions) { + if (tx.id().str() == swwo_peerplays_transaction_id) { + operation op = tx.operations[swwo_op_idx]; + transfer_operation t_op = op.get(); + + price asset_price = database.get(t_op.amount.asset_id).options.core_exchange_rate; + asset peerplays_asset = asset(t_op.amount.amount * asset_price.base.amount / asset_price.quote.amount); + + process_ok = (t_op.to == gpo.parameters.son_account()) && + (swwo->peerplays_from == t_op.from) && + (swwo->peerplays_asset == peerplays_asset); + break; + } + } + + object_id_type object_id = op_obj_idx_1.get().object_id; + std::string op_tx_str = op_obj_idx_1.get().transaction; + + const auto &st_idx = database.get_index_type().indices().get(); + const auto st = st_idx.find(object_id); + if (st == st_idx.end()) { + + std::string tx_str = ""; + + if (object_id.is()) { + const auto &idx = database.get_index_type().indices().get(); + const auto swwo = idx.find(object_id); + if (swwo != idx.end()) { + + std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str)); + hive::signed_transaction op_trx; + fc::raw::unpack(ss_trx, op_trx, 1000); + + uint64_t symbol = 0; + if (swwo->withdraw_currency == "HBD") { + symbol = hive::asset::hbd_symbol_ser; + } + if (swwo->withdraw_currency == "HIVE") { + symbol = hive::asset::hive_symbol_ser; + } + + hive::transfer_operation t_op; + t_op.from = "son-account"; + t_op.to = swwo->withdraw_address; + t_op.amount.amount = swwo->withdraw_amount; + t_op.amount.symbol = symbol; + t_op.memo = ""; + + hive::signed_transaction htrx; + htrx.ref_block_num = op_trx.ref_block_num; + htrx.ref_block_prefix = op_trx.ref_block_prefix; + htrx.set_expiration(op_trx.expiration); + + htrx.operations.push_back(t_op); + + std::stringstream ss; + fc::raw::pack(ss, htrx, 1000); + tx_str = boost::algorithm::hex(ss.str()); + } + } + + transaction_ok = (op_tx_str == tx_str); + } + } + + should_approve = process_ok && + transaction_ok; + break; + } + + case chain::operation::tag::value: { + should_approve = true; + son_id_type signer = op_obj_idx_0.get().signer; + std::string signature = op_obj_idx_0.get().signature; + sidechain_transaction_id_type sidechain_transaction_id = op_obj_idx_0.get().sidechain_transaction_id; + const auto &st_idx = database.get_index_type().indices().get(); + const auto sto = st_idx.find(sidechain_transaction_id); + if (sto == st_idx.end()) { + should_approve = false; + break; + } + + const auto &s_idx = database.get_index_type().indices().get(); + const auto son = s_idx.find(signer); + if (son == s_idx.end()) { + should_approve = false; + break; + } + + break; + } + + case chain::operation::tag::value: { + should_approve = true; + break; + } + + default: + should_approve = false; + elog("=================================================="); + elog("Proposal not considered for approval ${po}", ("po", po)); + elog("=================================================="); + } + + return should_approve; +} + +void sidechain_net_handler_hive::process_primary_wallet() { + const auto &swi = database.get_index_type().indices().get(); + const auto &active_sw = swi.rbegin(); + if (active_sw != swi.rend()) { + + if ((active_sw->addresses.find(sidechain) == active_sw->addresses.end()) || + (active_sw->addresses.at(sidechain).empty())) { + + if (proposal_exists(chain::operation::tag::value, active_sw->id)) { + return; + } + + const chain::global_property_object &gpo = database.get_global_properties(); + + auto active_sons = gpo.active_sons; + fc::flat_map account_auths; + uint32_t total_weight = 0; + for (const auto &active_son : active_sons) { + total_weight = total_weight + active_son.weight; + account_auths[active_son.sidechain_public_keys.at(sidechain)] = active_son.weight; + } + + std::string memo_key = node_rpc_client->get_account_memo_key("son-account"); + + if (memo_key.empty()) { + return; + } + + hive::authority active; + active.weight_threshold = total_weight * 2 / 3 + 1; + active.account_auths = account_auths; + + hive::account_update_operation auo; + auo.account = "son-account"; + auo.active = active; + auo.memo_key = hive::public_key_type(memo_key); + + std::string block_id_str = node_rpc_client->get_head_block_id(); + hive::block_id_type head_block_id(block_id_str); + + std::string head_block_time_str = node_rpc_client->get_head_block_time(); + time_point head_block_time = fc::time_point_sec::from_iso_string(head_block_time_str); + + hive::signed_transaction htrx; + htrx.set_reference_block(head_block_id); + htrx.set_expiration(head_block_time + fc::seconds(180)); + + htrx.operations.push_back(auo); + + std::stringstream ss; + fc::raw::pack(ss, htrx, 1000); + std::string tx_str = boost::algorithm::hex(ss.str()); + if (tx_str.empty()) { + return; + } + + proposal_create_operation proposal_op; + proposal_op.fee_paying_account = plugin.get_current_son_object().son_account; + uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3; + proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime); + + son_wallet_update_operation swu_op; + swu_op.payer = gpo.parameters.son_account(); + swu_op.son_wallet_id = active_sw->id; + swu_op.sidechain = sidechain; + swu_op.address = "son-account"; + + proposal_op.proposed_ops.emplace_back(swu_op); + + sidechain_transaction_create_operation stc_op; + stc_op.payer = gpo.parameters.son_account(); + stc_op.object_id = active_sw->id; + stc_op.sidechain = sidechain; + stc_op.transaction = tx_str; + stc_op.signers = gpo.active_sons; + + proposal_op.proposed_ops.emplace_back(stc_op); + + signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op); + try { + trx.validate(); + 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)); + } catch (fc::exception &e) { + elog("Sending proposal for son wallet update operation failed with exception ${e}", ("e", e.what())); + return; + } + } + } +} + +void sidechain_net_handler_hive::process_sidechain_addresses() { + const auto &sidechain_addresses_idx = database.get_index_type(); + const auto &sidechain_addresses_by_sidechain_idx = sidechain_addresses_idx.indices().get(); + 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; + op.payer = plugin.get_current_son_object().son_account; + op.sidechain_address_id = sao.id; + op.sidechain_address_account = sao.sidechain_address_account; + op.sidechain = sao.sidechain; + op.deposit_public_key = sao.deposit_public_key; + op.deposit_address = sao.withdraw_address; + op.deposit_address_data = sao.withdraw_address; + op.withdraw_public_key = sao.withdraw_public_key; + op.withdraw_address = sao.withdraw_address; + + signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op); + try { + trx.validate(); + 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)); + retval = true; + } catch (fc::exception &e) { + elog("Sending transaction for sidechain address update operation failed with exception ${e}", ("e", e.what())); + retval = false; + } + } + } + return retval; + }); +} + +bool sidechain_net_handler_hive::process_deposit(const son_wallet_deposit_object &swdo) { + const chain::global_property_object &gpo = database.get_global_properties(); + + price asset_price; + asset asset_to_issue; + if (swdo.sidechain_currency == "HBD") { + asset_price = database.get(database.get_global_properties().parameters.hbd_asset()).options.core_exchange_rate; + asset_to_issue = asset(swdo.peerplays_asset.amount * asset_price.quote.amount / asset_price.base.amount, database.get_global_properties().parameters.hbd_asset()); + } + if (swdo.sidechain_currency == "HIVE") { + asset_price = database.get(database.get_global_properties().parameters.hive_asset()).options.core_exchange_rate; + asset_to_issue = asset(swdo.peerplays_asset.amount * asset_price.quote.amount / asset_price.base.amount, database.get_global_properties().parameters.hive_asset()); + } + + proposal_create_operation proposal_op; + proposal_op.fee_paying_account = plugin.get_current_son_object().son_account; + uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3; + proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime); + + son_wallet_deposit_process_operation swdp_op; + swdp_op.payer = gpo.parameters.son_account(); + swdp_op.son_wallet_deposit_id = swdo.id; + proposal_op.proposed_ops.emplace_back(swdp_op); + + asset_issue_operation ai_op; + ai_op.fee = asset(2001000); + ai_op.issuer = gpo.parameters.son_account(); + ai_op.asset_to_issue = asset_to_issue; + ai_op.issue_to_account = swdo.peerplays_from; + proposal_op.proposed_ops.emplace_back(ai_op); + + signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op); + try { + trx.validate(); + 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; + } catch (fc::exception &e) { + elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what())); + return false; + } + + return false; +} + +bool sidechain_net_handler_hive::process_withdrawal(const son_wallet_withdraw_object &swwo) { + const chain::global_property_object &gpo = database.get_global_properties(); + + //===== + + uint64_t symbol = 0; + if (swwo.withdraw_currency == "HBD") { + symbol = hive::asset::hbd_symbol_ser; + } + if (swwo.withdraw_currency == "HIVE") { + symbol = hive::asset::hive_symbol_ser; + } + + hive::transfer_operation t_op; + t_op.from = "son-account"; + t_op.to = swwo.withdraw_address; + t_op.amount.amount = swwo.withdraw_amount; + t_op.amount.symbol = symbol; + t_op.memo = ""; + + std::string block_id_str = node_rpc_client->get_head_block_id(); + hive::block_id_type head_block_id(block_id_str); + + std::string head_block_time_str = node_rpc_client->get_head_block_time(); + time_point head_block_time = fc::time_point_sec::from_iso_string(head_block_time_str); + + hive::signed_transaction htrx; + htrx.set_reference_block(head_block_id); + htrx.set_expiration(head_block_time + fc::seconds(180)); + + htrx.operations.push_back(t_op); + + std::stringstream ss; + fc::raw::pack(ss, htrx, 1000); + std::string tx_str = boost::algorithm::hex(ss.str()); + if (tx_str.empty()) { + return false; + } + + //===== + + proposal_create_operation proposal_op; + proposal_op.fee_paying_account = plugin.get_current_son_object().son_account; + uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3; + proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime); + + son_wallet_withdraw_process_operation swwp_op; + swwp_op.payer = gpo.parameters.son_account(); + swwp_op.son_wallet_withdraw_id = swwo.id; + proposal_op.proposed_ops.emplace_back(swwp_op); + + sidechain_transaction_create_operation stc_op; + stc_op.payer = gpo.parameters.son_account(); + stc_op.object_id = swwo.id; + stc_op.sidechain = sidechain; + stc_op.transaction = tx_str; + stc_op.signers = gpo.active_sons; + proposal_op.proposed_ops.emplace_back(stc_op); + + signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op); + try { + trx.validate(); + 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; + } catch (fc::exception &e) { + elog("Sending proposal for withdraw sidechain transaction create operation failed with exception ${e}", ("e", e.what())); + return false; + } + + return false; +} + +std::string sidechain_net_handler_hive::process_sidechain_transaction(const sidechain_transaction_object &sto) { + std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction)); + hive::signed_transaction htrx; + fc::raw::unpack(ss_trx, htrx, 1000); + + std::string chain_id_str = node_rpc_client->get_chain_id(); + const hive::chain_id_type chain_id(chain_id_str); + + fc::optional privkey = graphene::utilities::wif_to_key(get_private_key(plugin.get_current_son_object().sidechain_public_keys.at(sidechain))); + signature_type st = htrx.sign(*privkey, chain_id); + + std::stringstream ss_st; + fc::raw::pack(ss_st, st, 1000); + std::string st_str = boost::algorithm::hex(ss_st.str()); + + return st_str; +} + +std::string sidechain_net_handler_hive::send_sidechain_transaction(const sidechain_transaction_object &sto) { + std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction)); + hive::signed_transaction htrx; + fc::raw::unpack(ss_trx, htrx, 1000); + + for (auto signature : sto.signatures) { + if (!signature.second.empty()) { + std::stringstream ss_st(boost::algorithm::unhex(signature.second)); + signature_type st; + fc::raw::unpack(ss_st, st, 1000); + htrx.signatures.push_back(st); + } + } + + std::string params = fc::json::to_string(htrx); + node_rpc_client->network_broadcast_api_broadcast_transaction(params); + + return htrx.id().str(); +} + +bool sidechain_net_handler_hive::settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) { + if (sto.object_id.is()) { + settle_amount.amount = 0; + return true; + } + + if (sto.sidechain_transaction.empty()) { + return false; + } + + std::string tx_str = node_rpc_client->account_history_api_get_transaction(sto.sidechain_transaction); + if (tx_str != "") { + + std::stringstream ss_tx(tx_str); + boost::property_tree::ptree tx_json; + boost::property_tree::read_json(ss_tx, tx_json); + + //const chain::global_property_object &gpo = database.get_global_properties(); + + std::string tx_txid = tx_json.get("result.transaction_id"); + uint32_t tx_block_num = tx_json.get("result.block_num"); + uint32_t last_irreversible_block = std::stoul(node_rpc_client->get_last_irreversible_block_num()); + + //std::string tx_address = addr.get_address(); + //int64_t tx_amount = -1; + + if (tx_block_num <= last_irreversible_block) { + if (sto.object_id.is()) { + auto swwo = database.get(sto.object_id); + if (swwo.withdraw_currency == "HBD") { + settle_amount = asset(swwo.withdraw_amount, database.get_global_properties().parameters.hbd_asset()); + } + if (swwo.withdraw_currency == "HIVE") { + settle_amount = asset(swwo.withdraw_amount, database.get_global_properties().parameters.hive_asset()); + } + return true; + } + } + } + return false; +} + +void sidechain_net_handler_hive::schedule_hive_listener() { + fc::time_point now = fc::time_point::now(); + int64_t time_to_next = 1000; + + fc::time_point next_wakeup(now + fc::milliseconds(time_to_next)); + + _listener_task = fc::schedule([this] { + hive_listener_loop(); + }, + next_wakeup, "SON Hive listener task"); +} + +void sidechain_net_handler_hive::hive_listener_loop() { + schedule_hive_listener(); + + std::string reply = node_rpc_client->database_api_get_dynamic_global_properties(); + if (!reply.empty()) { + std::stringstream ss(reply); + boost::property_tree::ptree json; + boost::property_tree::read_json(ss, json); + if (json.count("result")) { + uint64_t head_block_number = json.get("result.head_block_number"); + if (head_block_number != last_block_received) { + std::string event_data = std::to_string(head_block_number); + handle_event(event_data); + last_block_received = head_block_number; + } + } + } + + //std::string reply = node_rpc_client->get_last_irreversible_block_num(); + //if (!reply.empty()) { + // uint64_t last_irreversible_block = std::stoul(reply); + // if (last_irreversible_block != last_block_received) { + // std::string event_data = std::to_string(last_irreversible_block); + // handle_event(event_data); + // last_block_received = last_irreversible_block; + // } + //} +} + +void sidechain_net_handler_hive::handle_event(const std::string &event_data) { + std::string block = node_rpc_client->block_api_get_block(std::atoll(event_data.c_str())); + if (block != "") { + std::stringstream ss(block); + boost::property_tree::ptree block_json; + boost::property_tree::read_json(ss, block_json); + + size_t tx_idx = -1; + for (const auto &tx_ids_child : block_json.get_child("result.block.transactions")) { + boost::property_tree::ptree tx = tx_ids_child.second; + tx_idx = tx_idx + 1; + + size_t op_idx = -1; + for (const auto &ops : tx.get_child("operations")) { + const auto &op = ops.second; + op_idx = op_idx + 1; + + std::string operation_type = op.get("type"); + + if (operation_type == "transfer_operation") { + const auto &op_value = op.get_child("value"); + + std::string from = op_value.get("from"); + std::string to = op_value.get("to"); + + if (to == "son-account") { + + const auto &amount_child = op_value.get_child("amount"); + + uint64_t amount = amount_child.get("amount"); + //uint64_t precision = amount_child.get("precision"); + std::string nai = amount_child.get("nai"); + std::string sidechain_currency = ""; + price sidechain_currency_price = {}; + if ((nai == "@@000000013" /*?? HBD*/) || (nai == "@@000000013" /*TBD*/)) { + sidechain_currency = "HBD"; + sidechain_currency_price = database.get(database.get_global_properties().parameters.hbd_asset()).options.core_exchange_rate; + } + if ((nai == "@@000000021") /*?? HIVE*/ || (nai == "@@000000021" /*TESTS*/)) { + sidechain_currency = "HIVE"; + sidechain_currency_price = database.get(database.get_global_properties().parameters.hive_asset()).options.core_exchange_rate; + } + + std::string memo = op_value.get("memo"); + boost::trim(memo); + if (!memo.empty()) { + from = memo; + } + + const auto &sidechain_addresses_idx = database.get_index_type().indices().get(); + const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, from, time_point_sec::maximum())); + account_id_type accn = account_id_type(); + if (addr_itr == sidechain_addresses_idx.end()) { + const auto &account_idx = database.get_index_type().indices().get(); + const auto &account_itr = account_idx.find(from); + if (account_itr == account_idx.end()) { + continue; + } else { + accn = account_itr->id; + } + } else { + accn = addr_itr->sidechain_address_account; + } + + std::vector transaction_ids; + for (const auto &tx_ids_child : block_json.get_child("result.block.transaction_ids")) { + const auto &transaction_id = tx_ids_child.second.get_value(); + transaction_ids.push_back(transaction_id); + } + std::string transaction_id = transaction_ids.at(tx_idx); + + std::stringstream ss; + ss << "hive" + << "-" << transaction_id << "-" << op_idx; + std::string sidechain_uid = ss.str(); + + sidechain_event_data sed; + sed.timestamp = database.head_block_time(); + sed.block_num = database.head_block_num(); + sed.sidechain = sidechain; + sed.sidechain_uid = sidechain_uid; + sed.sidechain_transaction_id = transaction_id; + sed.sidechain_from = from; + sed.sidechain_to = to; + sed.sidechain_currency = sidechain_currency; + sed.sidechain_amount = amount; + sed.peerplays_from = accn; + sed.peerplays_to = database.get_global_properties().parameters.son_account(); + sed.peerplays_asset = asset(sed.sidechain_amount * sidechain_currency_price.base.amount / sidechain_currency_price.quote.amount); + sidechain_event_data_received(sed); + } + } + } + } + } +} + +}} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp index ecf3cc00..d5a9ec32 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp @@ -25,6 +25,15 @@ namespace graphene { namespace peerplays_sidechain { sidechain_net_handler_peerplays::sidechain_net_handler_peerplays(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) : sidechain_net_handler(_plugin, options) { sidechain = sidechain_type::peerplays; + //const auto &assets_by_symbol = database.get_index_type().indices().get(); + //const auto get_asset_id = [&assets_by_symbol](const string &symbol) { + // auto asset_itr = assets_by_symbol.find(symbol); + // FC_ASSERT(asset_itr != assets_by_symbol.end(), "Unable to find asset '${sym}'", ("sym", symbol)); + // return asset_itr->get_id(); + //}; + //tracked_assets.push_back(get_asset_id("PBTC")); + //tracked_assets.push_back(get_asset_id("PETH")); + //tracked_assets.push_back(get_asset_id("PEOS")); if (options.count("peerplays-private-key")) { const std::vector pub_priv_keys = options["peerplays-private-key"].as>(); @@ -37,10 +46,6 @@ sidechain_net_handler_peerplays::sidechain_net_handler_peerplays(peerplays_sidec private_keys[key_pair.first] = key_pair.second; } } - - database.applied_block.connect([&](const signed_block &b) { - on_applied_block(b); - }); } sidechain_net_handler_peerplays::~sidechain_net_handler_peerplays() { @@ -131,32 +136,34 @@ 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; - op.payer = plugin.get_current_son_object().son_account; - op.sidechain_address_id = sao.id; - op.sidechain_address_account = sao.sidechain_address_account; - op.sidechain = sao.sidechain; - op.deposit_public_key = sao.deposit_public_key; - op.deposit_address = sao.withdraw_address; - op.deposit_address_data = sao.withdraw_address; - op.withdraw_public_key = sao.withdraw_public_key; - op.withdraw_address = sao.withdraw_address; + op.payer = plugin.get_current_son_object().son_account; + op.sidechain_address_id = sao.id; + op.sidechain_address_account = sao.sidechain_address_account; + op.sidechain = sao.sidechain; + op.deposit_public_key = sao.deposit_public_key; + op.deposit_address = sao.withdraw_address; + op.deposit_address_data = sao.withdraw_address; + op.withdraw_public_key = sao.withdraw_public_key; + op.withdraw_address = sao.withdraw_address; - signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op); - try { - trx.validate(); - 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; - } catch (fc::exception &e) { - elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what())); - return false; - } + signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op); + try { + trx.validate(); + 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)); + retval = true; + } catch (fc::exception &e) { + elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what())); + retval = false; + } } } + return retval; }); return; } @@ -264,45 +271,23 @@ std::string sidechain_net_handler_peerplays::send_sidechain_transaction(const si return ""; } -int64_t sidechain_net_handler_peerplays::settle_sidechain_transaction(const sidechain_transaction_object &sto) { - int64_t settle_amount = 0; - return settle_amount; -} +bool sidechain_net_handler_peerplays::settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) { -void sidechain_net_handler_peerplays::on_applied_block(const signed_block &b) { - for (const auto &trx : b.transactions) { - size_t operation_index = -1; - for (auto op : trx.operations) { - operation_index = operation_index + 1; - if (op.which() == operation::tag::value) { - transfer_operation transfer_op = op.get(); - if (transfer_op.to != plugin.database().get_global_properties().parameters.son_account()) { - continue; - } - - std::stringstream ss; - ss << "peerplays" - << "-" << trx.id().str() << "-" << operation_index; - std::string sidechain_uid = ss.str(); - - sidechain_event_data sed; - sed.timestamp = database.head_block_time(); - sed.block_num = database.head_block_num(); - sed.sidechain = sidechain_type::peerplays; - sed.sidechain_uid = sidechain_uid; - sed.sidechain_transaction_id = trx.id().str(); - sed.sidechain_from = fc::to_string(transfer_op.from.space_id) + "." + fc::to_string(transfer_op.from.type_id) + "." + fc::to_string((uint64_t)transfer_op.from.instance); - sed.sidechain_to = fc::to_string(transfer_op.to.space_id) + "." + fc::to_string(transfer_op.to.type_id) + "." + fc::to_string((uint64_t)transfer_op.to.instance); - sed.sidechain_currency = fc::to_string(transfer_op.amount.asset_id.space_id) + "." + fc::to_string(transfer_op.amount.asset_id.type_id) + "." + fc::to_string((uint64_t)transfer_op.amount.asset_id.instance); - sed.sidechain_amount = transfer_op.amount.amount; - sed.peerplays_from = transfer_op.from; - sed.peerplays_to = transfer_op.to; - price asset_price = database.get(transfer_op.amount.asset_id).options.core_exchange_rate; - sed.peerplays_asset = asset(transfer_op.amount.amount * asset_price.base.amount / asset_price.quote.amount); - sidechain_event_data_received(sed); - } - } + if (sto.object_id.is()) { + settle_amount = asset(0); } + + if (sto.object_id.is()) { + //auto swdo = database.get(sto.object_id); + //settle_amount = asset(swdo.sidechain_amount, swdo.sidechain_currency); + } + + if (sto.object_id.is()) { + auto swwo = database.get(sto.object_id); + settle_amount = swwo.peerplays_asset; + } + + return true; } }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp index 962488a6..ff876b0c 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include namespace graphene { namespace peerplays_sidechain { @@ -10,6 +11,10 @@ namespace graphene { namespace peerplays_sidechain { sidechain_net_manager::sidechain_net_manager(peerplays_sidechain_plugin &_plugin) : plugin(_plugin), database(_plugin.database()) { + + //database.applied_block.connect([&](const signed_block &b) { + // on_applied_block(b); + //}); } sidechain_net_manager::~sidechain_net_manager() { @@ -26,6 +31,12 @@ bool sidechain_net_manager::create_handler(sidechain_type sidechain, const boost ret_val = true; break; } + case sidechain_type::hive: { + std::unique_ptr h = std::unique_ptr(new sidechain_net_handler_hive(plugin, options)); + net_handlers.push_back(std::move(h)); + ret_val = true; + break; + } case sidechain_type::peerplays: { std::unique_ptr h = std::unique_ptr(new sidechain_net_handler_peerplays(plugin, options)); net_handlers.push_back(std::move(h)); @@ -87,4 +98,7 @@ void sidechain_net_manager::settle_sidechain_transactions() { } } +void sidechain_net_manager::on_applied_block(const signed_block &b) { +} + }} // namespace graphene::peerplays_sidechain 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 ac7d8996..a7921b1f 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 { @@ -313,7 +318,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 */ @@ -325,14 +330,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 @@ -340,7 +345,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. * @@ -351,12 +356,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; @@ -392,7 +397,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 @@ -448,8 +453,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 @@ -457,7 +462,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. * @@ -533,21 +538,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. @@ -555,7 +560,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 @@ -568,7 +573,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(); @@ -603,13 +608,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 @@ -647,7 +652,7 @@ class wallet_api * @see suggest_brain_key() * * @param brain_key Brain key - * @param numberOfDesiredKeys Number of desired keys + * @param number_of_desired_keys Number of desired keys * @return A list of keys that are deterministically derived from the brainkey */ vector derive_owner_keys_from_brain_key(string brain_key, int number_of_desired_keys = 1) const; @@ -662,7 +667,12 @@ class wallet_api bool is_public_key_registered(string public_key) const; /** - * @param role - active | owner | memo + * Gets private key from password + * + * @param account Account name + * @param role Account role - active | owner | memo + * @param password Account password + * @return public/private key pair */ pair get_private_key_from_password( string account, string role, string password )const; @@ -678,7 +688,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() * @@ -741,6 +751,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'. @@ -781,7 +826,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,27 +900,33 @@ class wallet_api * that it exists in the blockchain. If it exists then it will report the amount received and * 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 + * @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 opt_memo - optional memo */ blind_receipt receive_blind_transfer( string confirmation_receipt, string opt_from, string opt_memo ); /** - * Transfers a public balance from @from to one or more blinded balances using a + * Transfers a public balance from from_account_id_or_name to one or more blinded balances using a * stealth transfer. + * + * @param from_account_id_or_name account id or name + * @param asset_symbol asset symbol + * @param to_amounts map from key or label to amount + * @param broadcast true to broadcast the transaction on the network + * @returns blind confirmation structure */ - 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 ); @@ -891,14 +942,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. * @@ -911,16 +962,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 @@ -937,12 +988,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 @@ -952,7 +1003,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, @@ -960,7 +1011,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 @@ -970,11 +1021,11 @@ class wallet_api * * @param buyer_account The account buying the asset for another asset. * @param base The name or id of the asset to buy. - * @param quote The name or id of the assest being offered as payment. + * @param quote The name or id of the asset being offered as payment. * @param rate The rate in base:quote at which you want to buy. * @param amount the amount of base you want to buy. * @param broadcast true to broadcast the transaction on the network. - * @param The signed transaction selling the funds. + * @returns The signed transaction buying the funds. */ signed_transaction buy( string buyer_account, string base, @@ -1015,14 +1066,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 @@ -1042,7 +1093,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. @@ -1060,8 +1111,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, @@ -1125,7 +1176,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 @@ -1153,7 +1204,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). * @@ -1194,7 +1245,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 @@ -1262,7 +1313,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. @@ -1273,7 +1324,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 @@ -1288,7 +1339,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 @@ -1427,6 +1478,12 @@ class wallet_api */ map list_active_sons(); + /** + * @brief Get SON network status + * @return SON network status description + */ + map get_son_network_status(); + /** * @brief Get active SON wallet * @return Active SON wallet object @@ -1454,6 +1511,7 @@ class wallet_api * @param account the name or id of the account who owns the address * @param sidechain a sidechain to whom address belongs * @param deposit_public_key sidechain public key used for deposit address + * @param deposit_address sidechain address for deposits * @param withdraw_public_key sidechain public key used for withdraw address * @param withdraw_address sidechain address for withdrawals * @param broadcast true to broadcast the transaction on the network @@ -1462,6 +1520,7 @@ class wallet_api signed_transaction add_sidechain_address(string account, sidechain_type sidechain, string deposit_public_key, + string deposit_address, string withdraw_public_key, string withdraw_address, bool broadcast = false); @@ -1522,7 +1581,7 @@ class wallet_api /** * Update a witness object owned by the given account. * - * @param witness The name of the witness's owner account. Also accepts the ID of the owner account or the ID of the witness. + * @param witness_name The name of the witness's owner account. Also accepts the ID of the owner account or the ID of the witness. * @param url Same as for create_witness. The empty string makes it remain the same. * @param block_signing_key The new block signing public key. The empty string makes it remain the same. * @param broadcast true if you wish to broadcast the transaction. @@ -1560,7 +1619,7 @@ class wallet_api * Update your votes for a worker * * @param account The account which will pay the fee and update votes. - * @param worker_vote_delta {"vote_for" : [...], "vote_against" : [...], "vote_abstain" : [...]} + * @param delta {"vote_for" : [...], "vote_against" : [...], "vote_abstain" : [...]} * @param broadcast true if you wish to broadcast the transaction. */ signed_transaction update_worker_votes( @@ -1621,7 +1680,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. @@ -1631,7 +1690,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 @@ -1693,12 +1752,12 @@ class wallet_api signed_transaction update_son_votes(string voting_account, std::vector sons_to_approve, std::vector sons_to_reject, - uint16_t desired_number_of_son, + uint16_t desired_number_of_sons, bool broadcast = false); /** 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. @@ -1708,7 +1767,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 @@ -1720,12 +1779,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 @@ -1740,7 +1799,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 @@ -1771,24 +1830,24 @@ 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 desired_number_of_witnesses desired number of witnesses + * @param desired_number_of_committee_members desired number of committee members * @param broadcast true if you wish to broadcast the transaction * @return the signed transaction changing your vote proxy settings */ @@ -1840,16 +1899,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 @@ -1874,7 +1933,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. @@ -1955,7 +2014,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, @@ -1982,7 +2041,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, @@ -2053,7 +2112,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 @@ -2090,6 +2149,7 @@ class wallet_api /** Creates a new tournament * @param creator the accout that is paying the fee to create the tournament * @param options the options detailing the specifics of the tournament + * @param broadcast true if you wish to broadcast the transaction * @return the signed version of the transaction */ signed_transaction tournament_create( string creator, tournament_options options, bool broadcast = false ); @@ -2129,7 +2189,7 @@ class wallet_api tournament_state state); /** Get specific information about a tournament - * @param tournament_id the ID of the tournament + * @param id the ID of the tournament */ tournament_object get_tournament(tournament_id_type id); @@ -2137,6 +2197,7 @@ class wallet_api * @param game_id the id of the game * @param player_account the name of the player * @param gesture rock, paper, or scissors + * @param broadcast true if you wish to broadcast the transaction * @return the signed version of the transaction */ signed_transaction rps_throw(game_id_type game_id, @@ -2175,6 +2236,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 // ///////// @@ -2188,6 +2250,9 @@ class wallet_api * @param revenue_split revenue split for the sale * @param is_transferable can transfer the NFT or not * @param is_sellable can sell NFT or not + * @param role_id account role id + * @param max_supply max supply of NTFs + * @param lottery_options lottery options * @param broadcast true to broadcast transaction to the network * @return Signed transaction transfering the funds */ @@ -2200,6 +2265,8 @@ class wallet_api bool is_transferable, bool is_sellable, optional role_id, + optional max_supply, + optional lottery_options, bool broadcast); /** @@ -2213,6 +2280,7 @@ class wallet_api * @param revenue_split revenue split for the sale * @param is_transferable can transfer the NFT or not * @param is_sellable can sell NFT or not + * @param role_id account role id * @param broadcast true to broadcast transaction to the network * @return Signed transaction transfering the funds */ @@ -2326,8 +2394,8 @@ class wallet_api /** * @brief Returns operator approved state for all NFT owned by owner - * @param owner NFT owner account ID - * @param token_id NFT ID + * @param owner_account_id_or_name NFT owner account ID or name + * @param operator_account_id_or_name NFT operator account ID or name * @return True if operator is approved for all NFT owned by owner, else False */ bool nft_is_approved_for_all(string owner_account_id_or_name, string operator_account_id_or_name) const; @@ -2337,6 +2405,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, @@ -2447,6 +2516,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) ) @@ -2475,7 +2546,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, @@ -2510,6 +2581,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) @@ -2551,6 +2624,7 @@ FC_API( graphene::wallet::wallet_api, (update_son_vesting_balances) (list_sons) (list_active_sons) + (get_son_network_status) (request_son_maintenance) (cancel_request_son_maintenance) (get_active_son_wallet) @@ -2669,6 +2743,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 7d4eb9f8..e876924e 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(); @@ -734,12 +734,16 @@ public: { return _remote_db->get_dynamic_global_properties(); } + std::string object_id_to_string(object_id_type id) const + { + std::string object_id = fc::to_string(id.space()) + + "." + fc::to_string(id.type()) + + "." + fc::to_string(id.instance()); + return object_id; + } std::string account_id_to_string(account_id_type id) const { - std::string account_id = fc::to_string(id.space_id) - + "." + fc::to_string(id.type_id) - + "." + fc::to_string(id.instance.value); - return account_id; + return object_id_to_string(id); } account_object get_account(account_id_type id) const { @@ -909,7 +913,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 +933,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 +976,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 +1133,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 +1339,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 +1629,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 +1640,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 +1648,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, @@ -2107,6 +2207,40 @@ public: return result; } FC_CAPTURE_AND_RETHROW() } + map get_son_network_status() + { try { + global_property_object gpo = get_global_properties(); + vector son_ids; + son_ids.reserve(gpo.active_sons.size()); + std::transform(gpo.active_sons.begin(), gpo.active_sons.end(), + std::inserter(son_ids, son_ids.end()), + [](const son_info& swi) { + return swi.son_id; + }); + + map result; + std::vector> son_objects = _remote_db->get_sons(son_ids); + for(auto son_obj: son_objects) { + string status; + if (son_obj) { + son_statistics_object sso = get_object(son_obj->statistics); + if (sso.last_active_timestamp + fc::seconds(gpo.parameters.son_heartbeat_frequency()) > time_point::now()) { + status = "OK, regular SON heartbeat"; + } else { + if (sso.last_active_timestamp + fc::seconds(gpo.parameters.son_down_time()) > time_point::now()) { + status = "OK, irregular SON heartbeat, but not triggering SON down proposal"; + } else { + status = "NOT OK, irregular SON heartbeat, triggering SON down proposal"; + } + } + } else { + status = "NOT OK, invalid SON id"; + } + result[son_obj->id] = status; + } + return result; + } FC_CAPTURE_AND_RETHROW() } + optional get_active_son_wallet() { try { return _remote_db->get_active_son_wallet(); @@ -2125,6 +2259,7 @@ public: signed_transaction add_sidechain_address(string account, sidechain_type sidechain, string deposit_public_key, + string deposit_address, string withdraw_public_key, string withdraw_address, bool broadcast /* = false */) @@ -2136,6 +2271,7 @@ public: op.sidechain_address_account = sidechain_address_account_id; op.sidechain = sidechain; op.deposit_public_key = deposit_public_key; + op.deposit_address = deposit_address; op.withdraw_public_key = withdraw_public_key; op.withdraw_address = withdraw_address; @@ -2407,13 +2543,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)); } @@ -2456,14 +2592,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) { @@ -2493,7 +2629,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 { @@ -2520,7 +2656,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 @@ -2646,7 +2782,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 { @@ -2657,7 +2793,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)); @@ -2673,7 +2809,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 @@ -2691,7 +2827,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; @@ -3300,7 +3436,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; @@ -3314,7 +3450,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); @@ -4127,7 +4263,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); @@ -4275,7 +4411,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 ); } @@ -4283,7 +4419,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; @@ -4334,9 +4470,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 ) @@ -4945,6 +5081,11 @@ map wallet_api::list_active_sons() return my->list_active_sons(); } +map wallet_api::get_son_network_status() +{ + return my->get_son_network_status(); +} + optional wallet_api::get_active_son_wallet() { return my->get_active_son_wallet(); @@ -4963,11 +5104,12 @@ vector> wallet_api::get_son_wallets(uint32_t limit) signed_transaction wallet_api::add_sidechain_address(string account, sidechain_type sidechain, string deposit_public_key, + string deposit_address, string withdraw_public_key, string withdraw_address, bool broadcast /* = false */) { - return my->add_sidechain_address(account, sidechain, deposit_public_key, withdraw_public_key, withdraw_address, broadcast); + return my->add_sidechain_address(account, sidechain, deposit_public_key, deposit_address, withdraw_public_key, withdraw_address, broadcast); } signed_transaction wallet_api::delete_sidechain_address(string account, @@ -5596,6 +5738,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); @@ -5621,8 +5782,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, @@ -5632,8 +5800,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, @@ -6284,22 +6459,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); } @@ -6362,7 +6537,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, @@ -6371,22 +6546,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); } @@ -6771,10 +6946,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 ) { @@ -6856,7 +7031,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)); @@ -6903,6 +7078,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); @@ -6926,6 +7103,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); @@ -7109,6 +7288,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/programs/witness_node/genesis.json b/programs/witness_node/genesis.json index d38f3e4e..1e0610f4 100644 --- a/programs/witness_node/genesis.json +++ b/programs/witness_node/genesis.json @@ -392,7 +392,7 @@ "son_deregister_time": 43200, "son_heartbeat_frequency": 180, "son_down_time": 360, - "maximum_son_count": 7 + "maximum_son_count": 15 } }, "initial_bts_accounts": [], 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/cli/son.cpp b/tests/cli/son.cpp index cf4fd8ed..1996c267 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -39,7 +39,7 @@ public: fixture_(fixture) { fixture_.init_nathan(); - fixture_.generate_blocks(HARDFORK_SON_TIME); + fixture_.generate_blocks(HARDFORK_SON_FOR_HIVE_TIME); fixture_.generate_block(); } @@ -121,10 +121,12 @@ BOOST_AUTO_TEST_CASE( create_sons ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); auto son1_obj = con.wallet_api_ptr->get_son("son1account"); @@ -153,6 +155,7 @@ BOOST_AUTO_TEST_CASE( cli_update_son ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::hive] = "hive account 1"; son_test_helper sth(*this); sth.create_son("sonmember", "http://sonmember", sidechain_public_keys); @@ -167,6 +170,7 @@ BOOST_AUTO_TEST_CASE( cli_update_son ) // update SON sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::hive] = "hive account 2"; con.wallet_api_ptr->update_son("sonmember", "http://sonmember_updated", "", sidechain_public_keys, true); son_data = con.wallet_api_ptr->get_son("sonmember"); @@ -197,10 +201,12 @@ BOOST_AUTO_TEST_CASE( son_voting ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); BOOST_TEST_MESSAGE("Voting for SONs"); @@ -292,6 +298,7 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture ) { sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); + sidechain_public_keys[sidechain_type::hive] = "hive account " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, @@ -366,10 +373,12 @@ BOOST_AUTO_TEST_CASE( list_son ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); auto res = con.wallet_api_ptr->list_sons("", 100); @@ -396,10 +405,12 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); BOOST_TEST_MESSAGE("Vote for 2 accounts with update_son_votes"); @@ -555,10 +566,12 @@ BOOST_AUTO_TEST_CASE( related_functions ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); gpo = con.wallet_api_ptr->get_global_properties(); @@ -592,6 +605,7 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture ) { sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); + sidechain_public_keys[sidechain_type::hive] = "hive account " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, @@ -659,6 +673,7 @@ BOOST_AUTO_TEST_CASE( maintenance_test ) { sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); + sidechain_public_keys[sidechain_type::hive] = "hive account " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, 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..02d8bdc1 --- /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/son_operations_tests.cpp b/tests/tests/son_operations_tests.cpp index 5fee05d5..1e3bb7e4 100644 --- a/tests/tests/son_operations_tests.cpp +++ b/tests/tests/son_operations_tests.cpp @@ -491,12 +491,32 @@ BOOST_AUTO_TEST_CASE( son_pay_test ) // Modify the transaction signed statistics of Alice's SON db.modify( *son_stats_obj1, [&]( son_statistics_object& _s) { - _s.txs_signed = 2; + _s.txs_signed[sidechain_type::bitcoin] = 2; + _s.txs_signed[sidechain_type::hive] = 4; + + _s.total_txs_signed[sidechain_type::bitcoin] = 2; + _s.total_txs_signed[sidechain_type::hive] = 4; + + _s.sidechain_txs_reported[sidechain_type::bitcoin] = 4; + _s.sidechain_txs_reported[sidechain_type::hive] = 8; + + _s.total_sidechain_txs_reported[sidechain_type::bitcoin] = 4; + _s.total_sidechain_txs_reported[sidechain_type::hive] = 8; }); // Modify the transaction signed statistics of Bob's SON db.modify( *son_stats_obj2, [&]( son_statistics_object& _s) { - _s.txs_signed = 3; + _s.txs_signed[sidechain_type::bitcoin] = 3; + _s.txs_signed[sidechain_type::hive] = 6; + + _s.total_txs_signed[sidechain_type::bitcoin] = 3; + _s.total_txs_signed[sidechain_type::hive] = 6; + + _s.sidechain_txs_reported[sidechain_type::bitcoin] = 6; + _s.sidechain_txs_reported[sidechain_type::hive] = 12; + + _s.total_sidechain_txs_reported[sidechain_type::bitcoin] = 6; + _s.total_sidechain_txs_reported[sidechain_type::hive] = 12; }); // Note the balances before the maintenance @@ -506,11 +526,23 @@ BOOST_AUTO_TEST_CASE( son_pay_test ) generate_blocks(dpo.next_maintenance_time); generate_block(); // Check if the signed transaction statistics are reset for both SONs - BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed, 0); - BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed, 0); + BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed.at(sidechain_type::bitcoin), 0); + BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed.at(sidechain_type::hive), 0); + BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed.at(sidechain_type::bitcoin), 0); + BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed.at(sidechain_type::hive), 0); + BOOST_REQUIRE_EQUAL(son_stats_obj1->sidechain_txs_reported.at(sidechain_type::bitcoin), 0); + BOOST_REQUIRE_EQUAL(son_stats_obj1->sidechain_txs_reported.at(sidechain_type::hive), 0); + BOOST_REQUIRE_EQUAL(son_stats_obj2->sidechain_txs_reported.at(sidechain_type::bitcoin), 0); + BOOST_REQUIRE_EQUAL(son_stats_obj2->sidechain_txs_reported.at(sidechain_type::hive), 0); - BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed, 2); - BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed, 3); + BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed.at(sidechain_type::bitcoin), 2); + BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed.at(sidechain_type::hive), 4); + BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed.at(sidechain_type::bitcoin), 3); + BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed.at(sidechain_type::hive), 6); + BOOST_REQUIRE_EQUAL(son_stats_obj1->total_sidechain_txs_reported.at(sidechain_type::bitcoin), 4); + BOOST_REQUIRE_EQUAL(son_stats_obj1->total_sidechain_txs_reported.at(sidechain_type::hive), 8); + BOOST_REQUIRE_EQUAL(son_stats_obj2->total_sidechain_txs_reported.at(sidechain_type::bitcoin), 6); + BOOST_REQUIRE_EQUAL(son_stats_obj2->total_sidechain_txs_reported.at(sidechain_type::hive), 12); // Check that Alice and Bob are paid for signing the transactions in the previous day/cycle BOOST_REQUIRE_EQUAL(db.get_balance(obj1->son_account, asset_id_type()).amount.value, 80+obj1_balance); BOOST_REQUIRE_EQUAL(db.get_balance(obj2->son_account, asset_id_type()).amount.value, 120+obj2_balance); 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; From dc04759686097c2b092a41eda65f69ce7c682a40 Mon Sep 17 00:00:00 2001 From: Bobinson K B Date: Fri, 10 Dec 2021 06:18:51 +0000 Subject: [PATCH 2/2] Revert "Merge branch 'merge-beatrice-to-master-2021-11' into 'master'" --- .gitignore | 1 - CMakeLists.txt | 74 +- README.md | 1 + bkup_CMakeCache.txt | 794 ++++++++++++ clang-format.sh | 4 - libraries/CMakeLists.txt | 12 +- libraries/app/CMakeLists.txt | 30 +- libraries/app/api.cpp | 23 +- libraries/app/application.cpp | 1 + libraries/app/database_api.cpp | 90 +- libraries/app/include/graphene/app/api.hpp | 4 - libraries/chain/CMakeLists.txt | 142 +- libraries/chain/asset_evaluator.cpp | 1 + libraries/chain/asset_object.cpp | 2 +- libraries/chain/database.cpp | 2 +- libraries/chain/db_balance.cpp | 6 +- libraries/chain/db_bet.cpp | 4 + libraries/chain/db_block.cpp | 3 +- libraries/chain/db_getter.cpp | 34 +- libraries/chain/db_init.cpp | 21 +- libraries/chain/db_maint.cpp | 160 +-- libraries/chain/db_management.cpp | 27 +- libraries/chain/db_notify.cpp | 22 - libraries/chain/db_update.cpp | 9 +- libraries/chain/hardfork.d/NFT.hf | 4 +- libraries/chain/hardfork.d/SON.hf | 2 +- libraries/chain/hardfork.d/SON_FOR_HIVE.hf | 4 - .../graphene/chain/account_role_object.hpp | 2 +- .../chain/include/graphene/chain/database.hpp | 2 - .../global_betting_statistics_object.hpp | 2 +- .../chain/include/graphene/chain/impacted.hpp | 2 +- .../graphene/chain/nft_lottery_evaluator.hpp | 39 - .../include/graphene/chain/nft_object.hpp | 100 +- .../chain/protocol/chain_parameters.hpp | 10 - .../graphene/chain/protocol/nft_lottery.hpp | 86 -- .../graphene/chain/protocol/nft_ops.hpp | 32 +- .../graphene/chain/protocol/operations.hpp | 8 +- .../graphene/chain/protocol/random_number.hpp | 25 - .../include/graphene/chain/protocol/types.hpp | 13 +- .../chain/random_number_evaluator.hpp | 19 - .../graphene/chain/random_number_object.hpp | 41 - .../graphene/chain/rbac_hardfork_visitor.hpp | 3 - .../include/graphene/chain/sidechain_defs.hpp | 4 +- .../chain/sidechain_transaction_object.hpp | 6 +- .../include/graphene/chain/son_object.hpp | 9 +- .../graphene/chain/vesting_balance_object.hpp | 20 +- libraries/chain/index.cpp | 43 + libraries/chain/nft_evaluator.cpp | 41 - libraries/chain/nft_lottery_evaluator.cpp | 145 --- libraries/chain/nft_lottery_object.cpp | 171 --- libraries/chain/proposal_evaluator.cpp | 12 - libraries/chain/protocol/competitor.cpp | 35 + libraries/chain/protocol/memo.cpp | 4 +- libraries/chain/protocol/nft.cpp | 4 - libraries/chain/protocol/nft_lottery.cpp | 38 - libraries/chain/random_number_evaluator.cpp | 24 - .../chain/sidechain_address_evaluator.cpp | 8 +- .../chain/sidechain_transaction_evaluator.cpp | 11 +- libraries/chain/son_object.cpp | 13 - .../chain/son_wallet_deposit_evaluator.cpp | 16 +- .../chain/son_wallet_withdraw_evaluator.cpp | 16 +- libraries/chain/tournament_object.cpp | 5 +- libraries/chain/transaction_object.cpp | 95 ++ .../db/include/graphene/db/undo_database.hpp | 12 +- libraries/db/undo_database.cpp | 12 - libraries/egenesis/CMakeLists.txt | 8 +- libraries/net/CMakeLists.txt | 8 +- libraries/net/node.cpp | 2 - libraries/plugins/CMakeLists.txt | 14 +- .../plugins/account_history/CMakeLists.txt | 2 +- .../plugins/accounts_list/CMakeLists.txt | 2 +- .../plugins/affiliate_stats/CMakeLists.txt | 2 +- libraries/plugins/bookie/CMakeLists.txt | 2 +- .../plugins/debug_witness/CMakeLists.txt | 2 +- libraries/plugins/delayed_node/CMakeLists.txt | 2 +- .../plugins/elasticsearch/CMakeLists.txt | 14 +- .../elasticsearch/elasticsearch_plugin.cpp | 109 +- .../elasticsearch/elasticsearch_plugin.hpp | 35 +- libraries/plugins/es_objects/CMakeLists.txt | 16 +- libraries/plugins/es_objects/es_objects.cpp | 416 +----- .../plugins/generate_genesis/CMakeLists.txt | 2 +- .../CMakeLists.txt | 2 +- .../grouped_orders/grouped_orders_plugin.cpp | 303 +++++ .../plugins/market_history/CMakeLists.txt | 2 +- .../peerplays_sidechain/CMakeLists.txt | 9 +- .../bitcoin/bitcoin_script.cpp | 1 - .../bitcoin/bitcoin_transaction.cpp | 1 - .../bitcoin/sign_bitcoin_transaction.cpp | 3 - .../peerplays_sidechain/common/rpc_client.cpp | 185 --- .../peerplays_sidechain/common/utils.cpp | 8 - .../peerplays_sidechain/hive/asset.cpp | 69 - .../peerplays_sidechain/hive/operations.cpp | 101 -- .../peerplays_sidechain/hive/transaction.cpp | 57 - .../peerplays_sidechain/hive/types.cpp | 73 -- .../peerplays_sidechain/common/rpc_client.hpp | 39 - .../peerplays_sidechain/common/utils.hpp | 5 - .../peerplays_sidechain/hive/asset.hpp | 41 - .../peerplays_sidechain/hive/authority.hpp | 33 - .../hive/hive_operations.hpp | 123 -- .../peerplays_sidechain/hive/operations.hpp | 69 - .../peerplays_sidechain/hive/transaction.hpp | 44 - .../peerplays_sidechain/hive/types.hpp | 72 -- .../peerplays_sidechain_plugin.hpp | 1 - .../sidechain_net_handler.hpp | 7 +- .../sidechain_net_handler_bitcoin.hpp | 14 +- .../sidechain_net_handler_hive.hpp | 68 - .../sidechain_net_handler_peerplays.hpp | 5 +- .../sidechain_net_manager.hpp | 2 - .../peerplays_sidechain_plugin.cpp | 98 +- .../sidechain_net_handler.cpp | 150 +-- .../sidechain_net_handler_bitcoin.cpp | 122 +- .../sidechain_net_handler_hive.cpp | 971 -------------- .../sidechain_net_handler_peerplays.cpp | 107 +- .../sidechain_net_manager.cpp | 14 - libraries/plugins/snapshot/CMakeLists.txt | 2 +- libraries/plugins/witness/CMakeLists.txt | 2 +- libraries/plugins/witness/witness.cpp | 6 +- libraries/wallet/CMakeLists.txt | 2 +- .../wallet/include/graphene/wallet/wallet.hpp | 255 ++-- libraries/wallet/wallet.cpp | 296 +---- programs/CMakeLists.txt | 4 +- programs/build_helpers/CMakeLists.txt | 4 +- programs/cli_wallet/CMakeLists.txt | 2 +- programs/debug_node/CMakeLists.txt | 2 +- programs/delayed_node/CMakeLists.txt | 2 +- programs/genesis_util/CMakeLists.txt | 6 +- .../js_operation_serializer/CMakeLists.txt | 2 +- programs/size_checker/CMakeLists.txt | 2 +- programs/witness_node/CMakeLists.txt | 2 +- programs/witness_node/genesis.json | 2 +- tests/CMakeLists.txt | 47 +- tests/betting/betting_tests.cpp | 1138 ++++++++++------- tests/cli/son.cpp | 17 +- tests/common/betting_test_markets.hpp | 141 +- tests/common/database_fixture.cpp | 43 +- tests/common/database_fixture.hpp | 4 +- tests/generate_empty_blocks/CMakeLists.txt | 2 +- .../bitcoin_transaction_tests.cpp | 1 - tests/tests/affiliate_tests.cpp | 48 +- tests/tests/block_tests.cpp | 2 +- tests/tests/confidential_tests.cpp | 1 + tests/tests/database_tests.cpp | 2 +- tests/tests/dividend_tests.cpp | 37 + tests/tests/gpos_tests.cpp | 230 +--- tests/tests/history_api_tests.cpp | 8 - tests/tests/lottery_tests.cpp | 5 +- tests/tests/nft_lottery_tests.cpp | 842 ------------ tests/tests/operation_tests.cpp | 1 + tests/tests/son_operations_tests.cpp | 44 +- tests/tests/voting_tests.cpp | 2 +- tests/tournament/tournament_tests.cpp | 6 +- 151 files changed, 2893 insertions(+), 6359 deletions(-) create mode 100644 bkup_CMakeCache.txt delete mode 100755 clang-format.sh delete mode 100644 libraries/chain/hardfork.d/SON_FOR_HIVE.hf delete mode 100644 libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp delete mode 100644 libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp delete mode 100644 libraries/chain/include/graphene/chain/protocol/random_number.hpp delete mode 100644 libraries/chain/include/graphene/chain/random_number_evaluator.hpp delete mode 100644 libraries/chain/include/graphene/chain/random_number_object.hpp create mode 100644 libraries/chain/index.cpp delete mode 100644 libraries/chain/nft_lottery_evaluator.cpp delete mode 100644 libraries/chain/nft_lottery_object.cpp create mode 100644 libraries/chain/protocol/competitor.cpp delete mode 100644 libraries/chain/protocol/nft_lottery.cpp delete mode 100644 libraries/chain/random_number_evaluator.cpp create mode 100644 libraries/chain/transaction_object.cpp create mode 100644 libraries/plugins/grouped_orders/grouped_orders_plugin.cpp delete mode 100644 libraries/plugins/peerplays_sidechain/common/rpc_client.cpp delete mode 100644 libraries/plugins/peerplays_sidechain/common/utils.cpp delete mode 100644 libraries/plugins/peerplays_sidechain/hive/asset.cpp delete mode 100644 libraries/plugins/peerplays_sidechain/hive/operations.cpp delete mode 100644 libraries/plugins/peerplays_sidechain/hive/transaction.cpp delete mode 100644 libraries/plugins/peerplays_sidechain/hive/types.cpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/rpc_client.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/asset.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/authority.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/operations.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/transaction.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_hive.hpp delete mode 100644 libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp delete mode 100644 tests/tests/nft_lottery_tests.cpp diff --git a/.gitignore b/.gitignore index 1a84b559..39b23163 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ data CMakeDoxyfile.in build -build__* libraries/utilities/git_revision.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 65541631..9c6be0bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ -# Defines Peerplays library target. -project( Peerplays ) +# Defines BitShares library target. +project( BitShares ) cmake_minimum_required( VERSION 2.8.12 ) -set( BLOCKCHAIN_NAME "Peerplays" ) +set( BLOCKCHAIN_NAME "BitShares" ) set( CLI_CLIENT_EXECUTABLE_NAME graphene_client ) -set( GUI_CLIENT_EXECUTABLE_NAME Peerplays ) +set( GUI_CLIENT_EXECUTABLE_NAME BitShares ) set( CUSTOM_URL_SCHEME "gcs" ) set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" ) @@ -22,34 +22,6 @@ 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" ) @@ -99,7 +71,7 @@ ENDIF() if( WIN32 ) - message( STATUS "Configuring Peerplays on WIN32") + message( STATUS "Configuring BitShares on WIN32") set( DB_VERSION 60 ) set( BDB_STATIC_LIBS 1 ) @@ -131,13 +103,20 @@ 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 Peerplays on OS X" ) + message( STATUS "Configuring BitShares 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 Peerplays on Linux" ) + message( STATUS "Configuring BitShares on Linux" ) set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -Wall" ) set( rt_library rt ) #set( pthread_library pthread) @@ -156,7 +135,7 @@ else( WIN32 ) # Apple AND Linux endif( APPLE ) if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp -Wno-parentheses -Wno-terminate -Wno-invalid-offsetof -Wno-sign-compare" ) 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" ) @@ -175,7 +154,7 @@ else( WIN32 ) # Apple AND Linux endif( WIN32 ) -set(ENABLE_COVERAGE_TESTING FALSE CACHE BOOL "Build Peerplays for code coverage analysis") +set(ENABLE_COVERAGE_TESTING FALSE CACHE BOOL "Build BitShares for code coverage analysis") if(ENABLE_COVERAGE_TESTING) SET(CMAKE_CXX_FLAGS "--coverage ${CMAKE_CXX_FLAGS}") @@ -184,13 +163,13 @@ endif() add_subdirectory( libraries ) -set(BUILD_PEERPLAYS_PROGRAMS TRUE CACHE BOOL "Build peerplays executables (witness node, cli wallet, etc)") +set(BUILD_BITSHARES_PROGRAMS TRUE CACHE BOOL "Build bitshares executables (witness node, cli wallet, etc)") add_subdirectory( programs ) -set(BUILD_PEERPLAYS_TESTS TRUE CACHE BOOL "Build peerplays unit tests") -if( BUILD_PEERPLAYS_TESTS ) +set(BUILD_BITSHARES_TESTS TRUE CACHE BOOL "Build bitshares unit tests") +if( BUILD_BITSHARES_TESTS ) add_subdirectory( tests ) -endif( BUILD_PEERPLAYS_TESTS ) +endif( BUILD_BITSHARES_TESTS ) if (ENABLE_INSTALLER) @@ -212,18 +191,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 Peerplays network") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A client for the Peerplays network") +set(CPACK_PACKAGE_DESCRIPTION "A client for the BitShares network") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A client for the BitShares network") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md") -set(CPACK_PACKAGE_INSTALL_DIRECTORY "Peerplays ${CPACK_PACKAGE_VERSION}") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "BitShares ${CPACK_PACKAGE_VERSION}") if(WIN32) SET(CPACK_GENERATOR "ZIP;NSIS") - set(CPACK_PACKAGE_NAME "Peerplays") # override above + set(CPACK_PACKAGE_NAME "BitShares") # override above set(CPACK_NSIS_EXECUTABLES_DIRECTORY .) - set(CPACK_NSIS_PACKAGE_NAME "Peerplays v${CPACK_PACKAGE_VERSION}") + set(CPACK_NSIS_PACKAGE_NAME "BitShares v${CPACK_PACKAGE_VERSION}") set(CPACK_NSIS_DISPLAY_NAME "${CPACK_NSIS_PACKAGE_NAME}") - set(CPACK_NSIS_DEFINES " !define MUI_STARTMENUPAGE_DEFAULTFOLDER \\\"Peerplays\\\"") + set(CPACK_NSIS_DEFINES " !define MUI_STARTMENUPAGE_DEFAULTFOLDER \\\"BitShares\\\"") # 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) @@ -241,4 +220,3 @@ endif(LINUX) include(CPack) endif(ENABLE_INSTALLER) - diff --git a/README.md b/README.md index e1ad6ef0..7173bcb1 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ make -j$(nproc) make install # this can install the executable files under /usr/local ``` +docker build -t peerplays . ## Docker image diff --git a/bkup_CMakeCache.txt b/bkup_CMakeCache.txt new file mode 100644 index 00000000..daa267e9 --- /dev/null +++ b/bkup_CMakeCache.txt @@ -0,0 +1,794 @@ +# This is the CMakeCache file. +# For build in directory: /home/pbattu/git/18.04/peerplays +# It was generated by CMake: /usr/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//No help, variable specified on the command line. +BOOST_ROOT:PATH=/home/pbattu/git/18.04/boost_1_67_0 + +//The threading library used by boost-thread +BOOST_THREAD_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpthread.so + +//Build bitshares executables (witness node, cli wallet, etc) +BUILD_BITSHARES_PROGRAMS:BOOL=TRUE + +//Build bitshares unit tests +BUILD_BITSHARES_TESTS:BOOL=TRUE + +//Build websocketpp examples. +BUILD_EXAMPLES:BOOL=OFF + +//Build websocketpp tests. +BUILD_TESTS:BOOL=OFF + +//Value Computed by CMake +BitShares_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays + +//Value Computed by CMake +BitShares_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays + +//Boost chrono library (debug) +Boost_CHRONO_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a + +//Boost chrono library (release) +Boost_CHRONO_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a + +//Boost context library (debug) +Boost_CONTEXT_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a + +//Boost context library (release) +Boost_CONTEXT_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a + +//Boost coroutine library (debug) +Boost_COROUTINE_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a + +//Boost coroutine library (release) +Boost_COROUTINE_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a + +//Boost date_time library (debug) +Boost_DATE_TIME_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a + +//Boost date_time library (release) +Boost_DATE_TIME_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a + +//The directory containing a CMake configuration file for Boost. +Boost_DIR:PATH=Boost_DIR-NOTFOUND + +//Boost filesystem library (debug) +Boost_FILESYSTEM_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a + +//Boost filesystem library (release) +Boost_FILESYSTEM_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a + +//Path to a file. +Boost_INCLUDE_DIR:PATH=/home/pbattu/git/18.04/boost_1_67_0/include + +//Boost iostreams library (debug) +Boost_IOSTREAMS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a + +//Boost iostreams library (release) +Boost_IOSTREAMS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a + +//Boost library directory +Boost_LIBRARY_DIR:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib + +//Boost library directory DEBUG +Boost_LIBRARY_DIR_DEBUG:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib + +//Boost library directory RELEASE +Boost_LIBRARY_DIR_RELEASE:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib + +//Boost locale library (debug) +Boost_LOCALE_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a + +//Boost locale library (release) +Boost_LOCALE_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a + +//Boost program_options library (debug) +Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a + +//Boost program_options library (release) +Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a + +//Boost serialization library (debug) +Boost_SERIALIZATION_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a + +//Boost serialization library (release) +Boost_SERIALIZATION_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a + +//Boost signals library (debug) +Boost_SIGNALS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a + +//Boost signals library (release) +Boost_SIGNALS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a + +//Boost system library (debug) +Boost_SYSTEM_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a + +//Boost system library (release) +Boost_SYSTEM_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a + +//Boost thread library (debug) +Boost_THREAD_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a + +//Boost thread library (release) +Boost_THREAD_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a + +//Boost unit_test_framework library (debug) +Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a + +//Boost unit_test_framework library (release) +Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a + +//ON or OFF +Boost_USE_STATIC_LIBS:STRING=ON + +//Path to a program. +CMAKE_AR:FILEPATH=/usr/bin/ar + +//Choose the type of build, options are: None(CMAKE_CXX_FLAGS or +// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel. +CMAKE_BUILD_TYPE:STRING=Debug + +//Enable/Disable color output during build. +CMAKE_COLOR_MAKEFILE:BOOL=ON + +//Configurations +CMAKE_CONFIGURATION_TYPES:STRING=Release;RelWithDebInfo;Debug + +//CXX compiler +CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++-5 + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-5 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-5 + +//Flags used by the compiler during all build types. +CMAKE_CXX_FLAGS:STRING= + +//Flags used by the compiler during debug builds. +CMAKE_CXX_FLAGS_DEBUG:STRING=-g + +//Flags used by the compiler during release builds for minimum +// size. +CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the compiler during release builds. +CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the compiler during release builds with debug info. +CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//C compiler +CMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc-5 + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-5 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-5 + +//Flags used by the compiler during all build types. +CMAKE_C_FLAGS:STRING= + +//Flags used by the compiler during debug builds. +CMAKE_C_FLAGS_DEBUG:STRING=-g + +//Flags used by the compiler during release builds for minimum +// size. +CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the compiler during release builds. +CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the compiler during release builds with debug info. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//Flags used by the linker. +CMAKE_EXE_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Enable/Disable output of compile commands during generation. +CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF + +//Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=/usr/local + +//Path to a program. +CMAKE_LINKER:FILEPATH=/usr/bin/ld + +//Path to a program. +CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make + +//Flags used by the linker during the creation of modules. +CMAKE_MODULE_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_NM:FILEPATH=/usr/bin/nm + +//Path to a program. +CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy + +//Path to a program. +CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=BitShares + +//Path to a program. +CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib + +//Flags used by the linker during the creation of dll's. +CMAKE_SHARED_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//If set, runtime paths are not added when installing shared libraries, +// but are added when building. +CMAKE_SKIP_INSTALL_RPATH:BOOL=NO + +//If set, runtime paths are not added when using shared libraries. +CMAKE_SKIP_RPATH:BOOL=NO + +//Flags used by the linker during the creation of static libraries. +CMAKE_STATIC_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_STRIP:FILEPATH=/usr/bin/strip + +//If this value is on, makefiles will be generated without the +// .SILENT directive, and all commands will be echoed to the console +// during the make. This is useful for debugging only. With Visual +// Studio IDE projects all commands are done without /nologo. +CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE + +//Path to a library. +CURSES_CURSES_LIBRARY:FILEPATH=CURSES_CURSES_LIBRARY-NOTFOUND + +//Path to a library. +CURSES_FORM_LIBRARY:FILEPATH=CURSES_FORM_LIBRARY-NOTFOUND + +//Path to a file. +CURSES_INCLUDE_PATH:PATH=CURSES_INCLUDE_PATH-NOTFOUND + +//Path to a library. +CURSES_NCURSES_LIBRARY:FILEPATH=CURSES_NCURSES_LIBRARY-NOTFOUND + +//Dot tool for use with Doxygen +DOXYGEN_DOT_EXECUTABLE:FILEPATH=DOXYGEN_DOT_EXECUTABLE-NOTFOUND + +//Doxygen documentation generation tool (http://www.doxygen.org) +DOXYGEN_EXECUTABLE:FILEPATH=DOXYGEN_EXECUTABLE-NOTFOUND + +//secp256k1 or openssl or mixed +ECC_IMPL:STRING=secp256k1 + +//Build BitShares for code coverage analysis +ENABLE_COVERAGE_TESTING:BOOL=FALSE + +//Build websocketpp with CPP11 features enabled. +ENABLE_CPP11:BOOL=ON + +//TRUE to try to use full zlib for compression, FALSE to use miniz.c +FC_USE_FULL_ZLIB:BOOL=FALSE + +//Git command line client +GIT_EXECUTABLE:FILEPATH=/usr/bin/git + +//location of the genesis.json to embed in the executable +GRAPHENE_EGENESIS_JSON:PATH=/home/pbattu/git/18.04/peerplays/genesis.json + +//The directory containing a CMake configuration file for Gperftools. +Gperftools_DIR:PATH=Gperftools_DIR-NOTFOUND + +//Installation directory for CMake files +INSTALL_CMAKE_DIR:PATH=lib/cmake/websocketpp + +//Installation directory for header files +INSTALL_INCLUDE_DIR:PATH=include + +//Log long API calls over websocket (ON OR OFF) +LOG_LONG_API:BOOL=ON + +//Max API execution time in ms +LOG_LONG_API_MAX_MS:STRING=1000 + +//API execution time in ms at which to warn +LOG_LONG_API_WARN_MS:STRING=750 + +//Path to a library. +OPENSSL_CRYPTO_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libcrypto.a + +//Path to a file. +OPENSSL_INCLUDE_DIR:PATH=/usr/include + +//Path to a library. +OPENSSL_SSL_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libssl.a + +//Path to a program. +PERL_EXECUTABLE:FILEPATH=/usr/bin/perl + +//pkg-config executable +PKG_CONFIG_EXECUTABLE:FILEPATH=/usr/bin/pkg-config + +//Path to a file. +READLINE_INCLUDE_DIR:PATH=/usr/include + +//Path to a library. +READLINE_LIBRARIES:FILEPATH=/usr/lib/x86_64-linux-gnu/libreadline.so + +//Path to a file. +Readline_INCLUDE_DIR:PATH=/usr/include + +//Path to a library. +Readline_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libreadline.so + +//Path to a file. +Readline_ROOT_DIR:PATH=/usr + +//OFF +UNITY_BUILD:BOOL=OFF + +//Path to a file. +ZLIB_INCLUDE_DIR:PATH=/usr/include + +//Path to a library. +ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND + +//Path to a library. +ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libz.so + +//Value Computed by CMake +fc_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc + +//Dependencies for the target +fc_LIB_DEPENDS:STATIC=general;-L/usr/local/lib;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a;general;/usr/lib/x86_64-linux-gnu/libpthread.so;general;/usr/lib/x86_64-linux-gnu/libssl.a;general;/usr/lib/x86_64-linux-gnu/libcrypto.a;general;/usr/lib/x86_64-linux-gnu/libz.so;general;dl;general;rt;general;/usr/lib/x86_64-linux-gnu/libreadline.so;general;secp256k1; + +//Value Computed by CMake +fc_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc + +//Dependencies for the target +graphene_account_history_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_accounts_list_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_affiliate_stats_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_app_LIB_DEPENDS:STATIC=general;graphene_market_history;general;graphene_account_history;general;graphene_accounts_list;general;graphene_affiliate_stats;general;graphene_chain;general;fc;general;graphene_db;general;graphene_net;general;graphene_time;general;graphene_utilities;general;graphene_debug_witness;general;graphene_bookie; + +//Dependencies for the target +graphene_bookie_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_chain_LIB_DEPENDS:STATIC=general;fc;general;graphene_db; + +//Dependencies for the target +graphene_db_LIB_DEPENDS:STATIC=general;fc; + +//Dependencies for the target +graphene_debug_witness_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_delayed_node_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_egenesis_brief_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; + +//Dependencies for the target +graphene_egenesis_full_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; + +//Dependencies for the target +graphene_egenesis_none_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; + +//Dependencies for the target +graphene_generate_genesis_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app;general;graphene_time; + +//Dependencies for the target +graphene_generate_uia_sharedrop_genesis_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app;general;graphene_time; + +//Dependencies for the target +graphene_market_history_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_net_LIB_DEPENDS:STATIC=general;fc;general;graphene_db; + +//Dependencies for the target +graphene_snapshot_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_time_LIB_DEPENDS:STATIC=general;fc; + +//Dependencies for the target +graphene_utilities_LIB_DEPENDS:STATIC=general;fc; + +//Dependencies for the target +graphene_wallet_LIB_DEPENDS:STATIC=general;graphene_app;general;graphene_net;general;graphene_chain;general;graphene_utilities;general;fc;general;dl; + +//Dependencies for the target +graphene_witness_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Value Computed by CMake +websocketpp_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc/vendor/websocketpp + +//Value Computed by CMake +websocketpp_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc/vendor/websocketpp + + +######################## +# INTERNAL cache entries +######################## + +//ADVANCED property for variable: BOOST_ROOT +BOOST_ROOT-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_CHRONO_LIBRARY_DEBUG +Boost_CHRONO_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_CHRONO_LIBRARY_RELEASE +Boost_CHRONO_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_CONTEXT_LIBRARY_DEBUG +Boost_CONTEXT_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_CONTEXT_LIBRARY_RELEASE +Boost_CONTEXT_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_COROUTINE_LIBRARY_DEBUG +Boost_COROUTINE_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_COROUTINE_LIBRARY_RELEASE +Boost_COROUTINE_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_DATE_TIME_LIBRARY_DEBUG +Boost_DATE_TIME_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_DATE_TIME_LIBRARY_RELEASE +Boost_DATE_TIME_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_DIR +Boost_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_FILESYSTEM_LIBRARY_DEBUG +Boost_FILESYSTEM_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_FILESYSTEM_LIBRARY_RELEASE +Boost_FILESYSTEM_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_INCLUDE_DIR +Boost_INCLUDE_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_IOSTREAMS_LIBRARY_DEBUG +Boost_IOSTREAMS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_IOSTREAMS_LIBRARY_RELEASE +Boost_IOSTREAMS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LIBRARY_DIR +Boost_LIBRARY_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LIBRARY_DIR_DEBUG +Boost_LIBRARY_DIR_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LIBRARY_DIR_RELEASE +Boost_LIBRARY_DIR_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LOCALE_LIBRARY_DEBUG +Boost_LOCALE_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LOCALE_LIBRARY_RELEASE +Boost_LOCALE_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG +Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE +Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SERIALIZATION_LIBRARY_DEBUG +Boost_SERIALIZATION_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SERIALIZATION_LIBRARY_RELEASE +Boost_SERIALIZATION_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SIGNALS_LIBRARY_DEBUG +Boost_SIGNALS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SIGNALS_LIBRARY_RELEASE +Boost_SIGNALS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SYSTEM_LIBRARY_DEBUG +Boost_SYSTEM_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SYSTEM_LIBRARY_RELEASE +Boost_SYSTEM_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_THREAD_LIBRARY_DEBUG +Boost_THREAD_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_THREAD_LIBRARY_RELEASE +Boost_THREAD_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG +Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE +Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_AR +CMAKE_AR-ADVANCED:INTERNAL=1 +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/home/pbattu/git/18.04/peerplays +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=10 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=2 +//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE +CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/usr/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest +//ADVANCED property for variable: CMAKE_CXX_COMPILER +CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR +CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB +CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS +CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG +CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL +CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER +CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_AR +CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB +CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//Executable file format +CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS +CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG +CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE +CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS +CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Unix Makefiles +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Have symbol pthread_create +CMAKE_HAVE_LIBC_CREATE:INTERNAL= +//Have library pthreads +CMAKE_HAVE_PTHREADS_CREATE:INTERNAL= +//Have library pthread +CMAKE_HAVE_PTHREAD_CREATE:INTERNAL=1 +//Have include pthread.h +CMAKE_HAVE_PTHREAD_H:INTERNAL=1 +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=/home/pbattu/git/18.04/peerplays +//Install .so files without execute permission. +CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1 +//ADVANCED property for variable: CMAKE_LINKER +CMAKE_LINKER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MAKE_PROGRAM +CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS +CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG +CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE +CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_NM +CMAKE_NM-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=37 +//ADVANCED property for variable: CMAKE_OBJCOPY +CMAKE_OBJCOPY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_OBJDUMP +CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RANLIB +CMAKE_RANLIB-ADVANCED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.10 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS +CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG +CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE +CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH +CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_RPATH +CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS +CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG +CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE +CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STRIP +CMAKE_STRIP-ADVANCED:INTERNAL=1 +//uname command +CMAKE_UNAME:INTERNAL=/bin/uname +//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE +CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CURSES_CURSES_LIBRARY +CURSES_CURSES_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CURSES_FORM_LIBRARY +CURSES_FORM_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CURSES_INCLUDE_PATH +CURSES_INCLUDE_PATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CURSES_NCURSES_LIBRARY +CURSES_NCURSES_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: DOXYGEN_DOT_EXECUTABLE +DOXYGEN_DOT_EXECUTABLE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: DOXYGEN_EXECUTABLE +DOXYGEN_EXECUTABLE-ADVANCED:INTERNAL=1 +//Details about finding OpenSSL +FIND_PACKAGE_MESSAGE_DETAILS_OpenSSL:INTERNAL=[/usr/lib/x86_64-linux-gnu/libcrypto.a][/usr/include][v1.1.0g()] +//Details about finding Perl +FIND_PACKAGE_MESSAGE_DETAILS_Perl:INTERNAL=[/usr/bin/perl][v5.26.1()] +//Details about finding Readline +FIND_PACKAGE_MESSAGE_DETAILS_Readline:INTERNAL=[/usr/include][/usr/lib/x86_64-linux-gnu/libreadline.so][v()] +//Details about finding Threads +FIND_PACKAGE_MESSAGE_DETAILS_Threads:INTERNAL=[TRUE][v()] +//Details about finding ZLIB +FIND_PACKAGE_MESSAGE_DETAILS_ZLIB:INTERNAL=[/usr/lib/x86_64-linux-gnu/libz.so][/usr/include][v1.2.11()] +//ADVANCED property for variable: GIT_EXECUTABLE +GIT_EXECUTABLE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: OPENSSL_CRYPTO_LIBRARY +OPENSSL_CRYPTO_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: OPENSSL_INCLUDE_DIR +OPENSSL_INCLUDE_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: OPENSSL_SSL_LIBRARY +OPENSSL_SSL_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: PERL_EXECUTABLE +PERL_EXECUTABLE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: PKG_CONFIG_EXECUTABLE +PKG_CONFIG_EXECUTABLE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Readline_INCLUDE_DIR +Readline_INCLUDE_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Readline_LIBRARY +Readline_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Readline_ROOT_DIR +Readline_ROOT_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: ZLIB_INCLUDE_DIR +ZLIB_INCLUDE_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: ZLIB_LIBRARY_DEBUG +ZLIB_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: ZLIB_LIBRARY_RELEASE +ZLIB_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//Last used BOOST_ROOT value. +_BOOST_ROOT_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0 +//Components requested for this build tree. +_Boost_COMPONENTS_SEARCHED:INTERNAL=chrono;context;coroutine;date_time;filesystem;iostreams;locale;program_options;serialization;signals;system;thread;unit_test_framework +//Last used Boost_INCLUDE_DIR value. +_Boost_INCLUDE_DIR_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/include +//Last used Boost_LIBRARY_DIR_DEBUG value. +_Boost_LIBRARY_DIR_DEBUG_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib +//Last used Boost_LIBRARY_DIR value. +_Boost_LIBRARY_DIR_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib +//Last used Boost_LIBRARY_DIR_RELEASE value. +_Boost_LIBRARY_DIR_RELEASE_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib +//Last used Boost_NAMESPACE value. +_Boost_NAMESPACE_LAST:INTERNAL=boost +//Last used Boost_USE_MULTITHREADED value. +_Boost_USE_MULTITHREADED_LAST:INTERNAL=TRUE +//Last used Boost_USE_STATIC_LIBS value. +_Boost_USE_STATIC_LIBS_LAST:INTERNAL=ON +_OPENSSL_CFLAGS:INTERNAL= +_OPENSSL_CFLAGS_I:INTERNAL= +_OPENSSL_CFLAGS_OTHER:INTERNAL= +_OPENSSL_FOUND:INTERNAL=1 +_OPENSSL_INCLUDEDIR:INTERNAL=/usr/include +_OPENSSL_INCLUDE_DIRS:INTERNAL= +_OPENSSL_LDFLAGS:INTERNAL=-lssl;-lcrypto +_OPENSSL_LDFLAGS_OTHER:INTERNAL= +_OPENSSL_LIBDIR:INTERNAL=/usr/lib/x86_64-linux-gnu +_OPENSSL_LIBRARIES:INTERNAL=ssl;crypto +_OPENSSL_LIBRARY_DIRS:INTERNAL= +_OPENSSL_LIBS:INTERNAL= +_OPENSSL_LIBS_L:INTERNAL= +_OPENSSL_LIBS_OTHER:INTERNAL= +_OPENSSL_LIBS_PATHS:INTERNAL= +_OPENSSL_PREFIX:INTERNAL=/usr +_OPENSSL_STATIC_CFLAGS:INTERNAL= +_OPENSSL_STATIC_CFLAGS_I:INTERNAL= +_OPENSSL_STATIC_CFLAGS_OTHER:INTERNAL= +_OPENSSL_STATIC_INCLUDE_DIRS:INTERNAL= +_OPENSSL_STATIC_LDFLAGS:INTERNAL=-lssl;-ldl;-lcrypto;-ldl +_OPENSSL_STATIC_LDFLAGS_OTHER:INTERNAL= +_OPENSSL_STATIC_LIBDIR:INTERNAL= +_OPENSSL_STATIC_LIBRARIES:INTERNAL=ssl;dl;crypto;dl +_OPENSSL_STATIC_LIBRARY_DIRS:INTERNAL= +_OPENSSL_STATIC_LIBS:INTERNAL= +_OPENSSL_STATIC_LIBS_L:INTERNAL= +_OPENSSL_STATIC_LIBS_OTHER:INTERNAL= +_OPENSSL_STATIC_LIBS_PATHS:INTERNAL= +_OPENSSL_VERSION:INTERNAL=1.1.0g +_OPENSSL_openssl_INCLUDEDIR:INTERNAL= +_OPENSSL_openssl_LIBDIR:INTERNAL= +_OPENSSL_openssl_PREFIX:INTERNAL= +_OPENSSL_openssl_VERSION:INTERNAL= +__pkg_config_arguments__OPENSSL:INTERNAL=QUIET;openssl +__pkg_config_checked__OPENSSL:INTERNAL=1 +prefix_result:INTERNAL=/usr/lib/x86_64-linux-gnu + diff --git a/clang-format.sh b/clang-format.sh deleted file mode 100755 index 6ab95eb9..00000000 --- a/clang-format.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -find ./libraries/plugins/peerplays_sidechain -regex ".*[c|h]pp" | xargs clang-format -i - diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index cf2355f1..18ca3130 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -1,10 +1,12 @@ -add_subdirectory( app ) -add_subdirectory( chain ) -add_subdirectory( db ) -add_subdirectory( egenesis ) add_subdirectory( fc ) +add_subdirectory( db ) +#add_subdirectory( deterministic_openssl_rand ) +add_subdirectory( chain ) +add_subdirectory( egenesis ) add_subdirectory( net ) -add_subdirectory( plugins ) +#add_subdirectory( p2p ) 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 52460c77..e0e5e6c2 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -4,19 +4,16 @@ 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 - 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_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_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" ) @@ -33,26 +30,3 @@ 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 eee02ea4..eb36cd9f 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -579,10 +579,7 @@ namespace graphene { namespace app { { FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); - 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) ); - + FC_ASSERT( limit <= 100 ); vector result; account_id_type account; try { @@ -630,16 +627,13 @@ namespace graphene { namespace app { { FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); - 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) ); - + FC_ASSERT( limit <= 100 ); 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); @@ -673,10 +667,7 @@ namespace graphene { namespace app { { FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); - 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) ); - + FC_ASSERT(limit <= 100); vector result; account_id_type account; try { @@ -806,16 +797,14 @@ 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 <= 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) ); + FC_ASSERT(limit <= 100); 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 6b95c937..46ebab04 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -381,6 +381,7 @@ 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 eb117b32..836af71e 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -235,17 +235,6 @@ 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; @@ -904,9 +893,7 @@ 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 <= api_limit_lookup_accounts, - "Number of querying accounts can not be greater than ${configured_limit}", - ("configured_limit", api_limit_lookup_accounts) ); + FC_ASSERT( limit <= 1000 ); const auto& accounts_by_name = _db.get_index_type().indices().get(); map result; @@ -943,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); @@ -1114,9 +1101,7 @@ 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 <= 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) ); + FC_ASSERT( limit <= 100 ); const auto& assets_by_symbol = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -1566,9 +1551,7 @@ 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 <= api_limit_get_order_book, - "Number of querying accounts can not be greater than ${configured_limit}", - ("configured_limit", api_limit_get_order_book) ); + FC_ASSERT( limit <= 50 ); order_book result; result.base = base; @@ -1630,9 +1613,7 @@ vector database_api_impl::get_trade_history( const string& base, fc::time_point_sec stop, unsigned limit )const { - 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) ); + FC_ASSERT( limit <= 100 ); auto assets = lookup_asset_symbols( {base, quote} ); FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) ); @@ -1751,9 +1732,7 @@ 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 <= api_limit_lookup_witness_accounts, - "Number of querying accounts can not be greater than ${configured_limit}", - ("configured_limit", api_limit_lookup_witness_accounts) ); + FC_ASSERT( limit <= 1000 ); 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 @@ -1829,9 +1808,7 @@ 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 <= 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) ); + FC_ASSERT( limit <= 1000 ); 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 @@ -2585,8 +2562,18 @@ 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 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) @@ -2596,6 +2583,7 @@ 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(); @@ -2606,9 +2594,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; @@ -2940,9 +2928,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -2962,9 +2948,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -2990,9 +2974,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3019,9 +3001,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& oh_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3041,9 +3021,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3067,9 +3045,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& offers_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3104,9 +3080,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& oh_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3127,9 +3101,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& oh_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -3151,9 +3123,7 @@ 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 <= api_limit_all_offers_count, - "Number of querying offers can not be greater than ${configured_limit}", - ("configured_limit", api_limit_all_offers_count) ); + FC_ASSERT( limit <= 100 ); const auto& oh_idx = _db.get_index_type().indices().get(); vector result; result.reserve(limit); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index e4329141..4adf73a3 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -150,9 +150,6 @@ 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; @@ -357,7 +354,6 @@ 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/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 4054878c..0a0e9c56 100755 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -8,29 +8,143 @@ add_dependencies( build_hardfork_hpp cat-parts ) file(GLOB HEADERS "include/graphene/chain/*.hpp") file(GLOB PROTOCOL_HEADERS "include/graphene/chain/protocol/*.hpp") -file(GLOB CPP_FILES "*.cpp") -file(GLOB PROTOCOL_CPP_FILES "protocol/*.cpp") - -#if( GRAPHENE_DISABLE_UNITY_BUILD ) - list(FILTER CPP_FILES EXCLUDE REGEX "[/]database[.]cpp$") - #message ("--- ${CPP_FILES}") +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 + ) message( STATUS "Graphene database unity build disabled" ) -#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 ) +else( GRAPHENE_DISABLE_UNITY_BUILD ) + set( GRAPHENE_DB_FILES + database.cpp ) + 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 - ${CPP_FILES} - ${PROTOCOL_CPP_FILES} + + # 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 + ${HEADERS} ${PROTOCOL_HEADERS} "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" ) add_dependencies( graphene_chain build_hardfork_hpp ) -target_link_libraries( graphene_chain graphene_db ) +target_link_libraries( graphene_chain fc 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 0591da54..0c7a458d 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -597,6 +597,7 @@ 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 70adbde8..79ad88ad 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( size_t c = 0; c < winner_numbers.size(); ++c ) { + for( int 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 8c1287c3..1e124902 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 27a7e79e..55729050 100644 --- a/libraries/chain/db_balance.cpp +++ b/libraries/chain/db_balance.cpp @@ -140,10 +140,8 @@ void database::adjust_sweeps_vesting_balance(account_id_type account, int64_t de b.balance = delta; }); } else { - 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)); - } + 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)); 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 6b14f4ff..8c3e1357 100644 --- a/libraries/chain/db_bet.cpp +++ b/libraries/chain/db_bet.cpp @@ -303,6 +303,8 @@ 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); @@ -535,9 +537,11 @@ 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 67601c2e..21701a25 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -715,8 +715,7 @@ 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 78740c9b..57a72e7f 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,38 +315,6 @@ 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; -} - bool database::is_asset_creation_allowed(const string &symbol) { time_point_sec now = head_block_time(); diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 724cad85..43ba381d 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include @@ -95,14 +94,12 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include @@ -206,12 +203,6 @@ 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); @@ -304,9 +295,6 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); - register_evaluator(); - register_evaluator(); - register_evaluator(); register_evaluator(); register_evaluator(); register_evaluator(); @@ -326,7 +314,6 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); - register_evaluator(); } void database::initialize_indexes() @@ -416,9 +403,7 @@ 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 >(); } @@ -948,6 +933,7 @@ 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() ) { @@ -959,6 +945,7 @@ 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", @@ -970,6 +957,10 @@ 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 3f68d598..0d585605 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 { @@ -84,7 +84,7 @@ vector> database::sort_votable_objects< std::vector> refs; for( auto& son : all_sons ) { - if(son.has_valid_config(head_block_time()) && son.status != son_status::deregistered) + if(son.has_valid_config() && son.status != son_status::deregistered) { refs.push_back(std::cref(son)); } @@ -210,29 +210,20 @@ void database::pay_sons() if( now < HARDFORK_SON2_TIME ) { son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id]); } - uint64_t txs_signed = 0; - for (const auto &ts : s.txs_signed) { - txs_signed = txs_signed + ts.second; - } - weighted_total_txs_signed += (txs_signed * son_weight); + weighted_total_txs_signed += (s.txs_signed * son_weight); }); // Now pay off each SON proportional to the number of transactions signed. get_index_type().inspect_all_objects([this, &weighted_total_txs_signed, &dpo, &son_budget, &get_weight, &get_weight_before_son2_hf, &now](const object& o) { const son_statistics_object& s = static_cast(o); - uint64_t txs_signed = 0; - for (const auto &ts : s.txs_signed) { - txs_signed = txs_signed + ts.second; - } - - if(txs_signed > 0){ + if(s.txs_signed > 0){ const auto& idx = get_index_type().indices().get(); auto son_obj = idx.find( s.owner ); auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id]); if( now < HARDFORK_SON2_TIME ) { son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id]); } - share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed; + share_type pay = (s.txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed; modify( *son_obj, [&]( son_object& _son_obj) { _son_obj.pay_son_fee(pay, *this); @@ -245,9 +236,8 @@ void database::pay_sons() //Reset the tx counter in each son statistics object modify( s, [&]( son_statistics_object& _s) { - for (const auto &ts : s.txs_signed) { - _s.txs_signed.at(ts.first) = 0; - } + _s.total_txs_signed += _s.txs_signed; + _s.txs_signed = 0; }); } }); @@ -277,13 +267,11 @@ void database::update_son_metrics(const vector& curr_active_sons) bool is_active_son = (std::find(current_sons.begin(), current_sons.end(), son.id) != current_sons.end()); modify( stats, [&]( son_statistics_object& _stats ) { - if(is_active_son) { - _stats.total_voted_time = _stats.total_voted_time + get_global_properties().parameters.maintenance_interval; - } _stats.total_downtime += _stats.current_interval_downtime; _stats.current_interval_downtime = 0; - for (const auto &str : _stats.sidechain_txs_reported) { - _stats.sidechain_txs_reported.at(str.first) = 0; + if(is_active_son) + { + _stats.total_voted_time = _stats.total_voted_time + get_global_properties().parameters.maintenance_interval; } }); } @@ -605,7 +593,7 @@ void database::update_active_committee_members() update_committee_member_total_votes( cm ); } } - + // Update committee authorities if( !committee_members.empty() ) { @@ -1218,6 +1206,7 @@ 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(); @@ -1255,13 +1244,13 @@ double database::calculate_vesting_factor(const account_object& stake_account) // variables needed const auto number_of_subperiods = vesting_period / vesting_subperiod; double vesting_factor; - + // get in what sub period we are uint32_t current_subperiod = get_gpos_current_subperiod(); - + if(current_subperiod == 0 || current_subperiod > number_of_subperiods) return 0; - // On starting new vesting period, all votes become zero until someone votes, To avoid a situation of zero votes, + // On starting new vesting period, all votes become zero until someone votes, To avoid a situation of zero votes, // changes were done to roll in GPOS rules, the vesting factor will be 1 for whoever votes in 6th sub-period of last vesting period // BLOCKBACK-174 fix if(current_subperiod == 1 && this->head_block_time() >= HARDFORK_GPOS_TIME + vesting_period) //Applicable only from 2nd vesting period @@ -1410,6 +1399,7 @@ 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)); @@ -1424,6 +1414,22 @@ 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) @@ -1877,6 +1883,7 @@ 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; @@ -1937,7 +1944,10 @@ void database::perform_son_tasks() a.options.market_fee_percent = 500; // 5% a.options.issuer_permissions = UIA_ASSET_ISSUER_PERMISSION_MASK; a.options.flags = asset_issuer_permission_flags::charge_market_fee | - asset_issuer_permission_flags::override_authority; + //asset_issuer_permission_flags::white_list | + asset_issuer_permission_flags::override_authority | + asset_issuer_permission_flags::transfer_restricted | + asset_issuer_permission_flags::disable_confidential; a.options.core_exchange_rate.base.amount = 100000; a.options.core_exchange_rate.base.asset_id = asset_id_type(0); a.options.core_exchange_rate.quote.amount = 2500; // CoinMarketCap approx value @@ -1954,74 +1964,6 @@ void database::perform_son_tasks() gpo.pending_parameters->extensions.value.btc_asset = btc_asset.get_id(); }); } - // create HBD asset here because son_account is the issuer of the HBD - if (gpo.parameters.hbd_asset() == asset_id_type() && head_block_time() >= HARDFORK_SON_FOR_HIVE_TIME) - { - const asset_dynamic_data_object& dyn_asset = - create([](asset_dynamic_data_object& a) { - a.current_supply = 0; - }); - - const asset_object& hbd_asset = - create( [&gpo, &dyn_asset]( asset_object& a ) { - a.symbol = "HBD"; - a.precision = 3; - a.issuer = gpo.parameters.son_account(); - a.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; - a.options.market_fee_percent = 500; // 5% - a.options.issuer_permissions = UIA_ASSET_ISSUER_PERMISSION_MASK; - a.options.flags = asset_issuer_permission_flags::charge_market_fee | - asset_issuer_permission_flags::override_authority; - a.options.core_exchange_rate.base.amount = 100000; - a.options.core_exchange_rate.base.asset_id = asset_id_type(0); - a.options.core_exchange_rate.quote.amount = 2500; // CoinMarketCap approx value - a.options.core_exchange_rate.quote.asset_id = a.id; - a.options.whitelist_authorities.clear(); // accounts allowed to use asset, if not empty - a.options.blacklist_authorities.clear(); // accounts who can blacklist other accounts to use asset, if white_list flag is set - a.options.whitelist_markets.clear(); // might be traded with - a.options.blacklist_markets.clear(); // might not be traded with - a.dynamic_asset_data_id = dyn_asset.id; - }); - modify( gpo, [&hbd_asset]( global_property_object& gpo ) { - gpo.parameters.extensions.value.hbd_asset = hbd_asset.get_id(); - if( gpo.pending_parameters ) - gpo.pending_parameters->extensions.value.hbd_asset = hbd_asset.get_id(); - }); - } - // create HIVE asset here because son_account is the issuer of the HIVE - if (gpo.parameters.hive_asset() == asset_id_type() && head_block_time() >= HARDFORK_SON_FOR_HIVE_TIME) - { - const asset_dynamic_data_object& dyn_asset = - create([](asset_dynamic_data_object& a) { - a.current_supply = 0; - }); - - const asset_object& hive_asset = - create( [&gpo, &dyn_asset]( asset_object& a ) { - a.symbol = "HIVE"; - a.precision = 3; - a.issuer = gpo.parameters.son_account(); - a.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; - a.options.market_fee_percent = 500; // 5% - a.options.issuer_permissions = UIA_ASSET_ISSUER_PERMISSION_MASK; - a.options.flags = asset_issuer_permission_flags::charge_market_fee | - asset_issuer_permission_flags::override_authority; - a.options.core_exchange_rate.base.amount = 100000; - a.options.core_exchange_rate.base.asset_id = asset_id_type(0); - a.options.core_exchange_rate.quote.amount = 2500; // CoinMarketCap approx value - a.options.core_exchange_rate.quote.asset_id = a.id; - a.options.whitelist_authorities.clear(); // accounts allowed to use asset, if not empty - a.options.blacklist_authorities.clear(); // accounts who can blacklist other accounts to use asset, if white_list flag is set - a.options.whitelist_markets.clear(); // might be traded with - a.options.blacklist_markets.clear(); // might not be traded with - a.dynamic_asset_data_id = dyn_asset.id; - }); - modify( gpo, [&hive_asset]( global_property_object& gpo ) { - gpo.parameters.extensions.value.hive_asset = hive_asset.get_id(); - if( gpo.pending_parameters ) - gpo.pending_parameters->extensions.value.hive_asset = hive_asset.get_id(); - }); - } // Pay the SONs if (head_block_time() >= HARDFORK_SON_TIME) { @@ -2082,7 +2024,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 = @@ -2094,7 +2036,19 @@ 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 ) @@ -2191,7 +2145,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g } } } tally_helper(*this, gpo); - + perform_account_maintenance( tally_helper ); struct clear_canary { clear_canary(vector& target): target(target){} @@ -2237,7 +2191,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g if( !p.pending_parameters->extensions.value.gpos_subperiod.valid() ) p.pending_parameters->extensions.value.gpos_subperiod = p.parameters.extensions.value.gpos_subperiod; if( !p.pending_parameters->extensions.value.gpos_vesting_lockin_period.valid() ) - p.pending_parameters->extensions.value.gpos_vesting_lockin_period = p.parameters.extensions.value.gpos_vesting_lockin_period; + p.pending_parameters->extensions.value.gpos_vesting_lockin_period = p.parameters.extensions.value.gpos_vesting_lockin_period; if( !p.pending_parameters->extensions.value.rbac_max_permissions_per_account.valid() ) p.pending_parameters->extensions.value.rbac_max_permissions_per_account = p.parameters.extensions.value.rbac_max_permissions_per_account; if( !p.pending_parameters->extensions.value.rbac_max_account_authority_lifetime.valid() ) @@ -2270,10 +2224,6 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g p.pending_parameters->extensions.value.btc_asset = p.parameters.extensions.value.btc_asset; if( !p.pending_parameters->extensions.value.maximum_son_count.valid() ) p.pending_parameters->extensions.value.maximum_son_count = p.parameters.extensions.value.maximum_son_count; - if( !p.pending_parameters->extensions.value.hbd_asset.valid() ) - p.pending_parameters->extensions.value.hbd_asset = p.parameters.extensions.value.hbd_asset; - if( !p.pending_parameters->extensions.value.hive_asset.valid() ) - p.pending_parameters->extensions.value.hive_asset = p.parameters.extensions.value.hive_asset; p.parameters = std::move(*p.pending_parameters); p.pending_parameters.reset(); } diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index e82602b1..c6380b8c 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -108,6 +107,7 @@ 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,7 +123,8 @@ void database::reindex( fc::path data_dir ) } for( uint32_t i = head_block_num() + 1; i <= last_block_num; ++i ) { - if( i % 10000 == 0 ) + 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() ); @@ -305,24 +306,6 @@ 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 c5986fad..06ffdee5 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -24,7 +24,6 @@ #include -#include #include #include #include @@ -42,10 +41,6 @@ #include #include #include -#include -#include -#include -#include using namespace fc; @@ -364,13 +359,6 @@ 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 ); } @@ -428,9 +416,6 @@ 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 ) { @@ -543,9 +528,6 @@ 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 ) @@ -600,10 +582,6 @@ 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 0476982c..2e896070 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -26,18 +26,16 @@ #include #include -#include -#include #include #include #include -#include #include -#include -#include #include #include #include +#include +#include +#include #include @@ -48,6 +46,7 @@ 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/hardfork.d/NFT.hf b/libraries/chain/hardfork.d/NFT.hf index 7ab75966..0a540a33 100644 --- a/libraries/chain/hardfork.d/NFT.hf +++ b/libraries/chain/hardfork.d/NFT.hf @@ -1,4 +1,4 @@ -// NFT HARDFORK 2020-12-21 00:00:00 GMT +// GPOS HARDFORK 2020-12-21 00:00:00 GMT #ifndef HARDFORK_NFT_TIME #define HARDFORK_NFT_TIME (fc::time_point_sec( 1608508800 )) -#endif \ No newline at end of file +#endif diff --git a/libraries/chain/hardfork.d/SON.hf b/libraries/chain/hardfork.d/SON.hf index 4c951f89..ee75fbe8 100644 --- a/libraries/chain/hardfork.d/SON.hf +++ b/libraries/chain/hardfork.d/SON.hf @@ -1,4 +1,4 @@ -// SON HARDFORK HARDFORK 2020-12-21 00:00:00 GMT +// GPOS HARDFORK 2020-12-21 00:00:00 GMT #ifndef HARDFORK_SON_TIME #define HARDFORK_SON_TIME (fc::time_point_sec( 1608508800 )) #endif diff --git a/libraries/chain/hardfork.d/SON_FOR_HIVE.hf b/libraries/chain/hardfork.d/SON_FOR_HIVE.hf deleted file mode 100644 index 8457636b..00000000 --- a/libraries/chain/hardfork.d/SON_FOR_HIVE.hf +++ /dev/null @@ -1,4 +0,0 @@ -// Saturday, December 11, 2021 0:00:00 -#ifndef HARDFORK_SON_FOR_HIVE_TIME -#define HARDFORK_SON_FOR_HIVE_TIME (fc::time_point_sec( 1639180800 )) -#endif diff --git a/libraries/chain/include/graphene/chain/account_role_object.hpp b/libraries/chain/include/graphene/chain/account_role_object.hpp index ccdfc9bc..2b3be409 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)) + (owner)(name)(metadata)(allowed_operations)(whitelisted_accounts)(valid_to)) \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 50975174..8c467ac0 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -286,7 +286,6 @@ 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 //////////////////// @@ -326,7 +325,6 @@ 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 6ded103a..7c557be5 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 = 0; + uint32_t number_of_active_events; map total_amount_staked; }; diff --git a/libraries/chain/include/graphene/chain/impacted.hpp b/libraries/chain/include/graphene/chain/impacted.hpp index 3e070ce6..fae276f7 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 +} } // graphene::app \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp b/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp deleted file mode 100644 index 0839cbbd..00000000 --- a/libraries/chain/include/graphene/chain/nft_lottery_evaluator.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#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 fe026da5..6a150852 100644 --- a/libraries/chain/include/graphene/chain/nft_object.hpp +++ b/libraries/chain/include/graphene/chain/nft_object.hpp @@ -6,29 +6,6 @@ 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: @@ -44,21 +21,6 @@ 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 @@ -74,23 +36,8 @@ 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< @@ -102,34 +49,6 @@ 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 > - > > > >; @@ -167,23 +86,8 @@ 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) @@ -193,9 +97,7 @@ FC_REFLECT_DERIVED( graphene::chain::nft_metadata_object, (graphene::db::object) (revenue_split) (is_transferable) (is_sellable) - (account_role) - (max_supply) - (lottery_data) ) + (account_role) ) FC_REFLECT_DERIVED( graphene::chain::nft_object, (graphene::db::object), (nft_metadata_id) diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index 3a11e99f..c24a0576 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -68,8 +68,6 @@ namespace graphene { namespace chain { optional < account_id_type > son_account = GRAPHENE_NULL_ACCOUNT; optional < asset_id_type > btc_asset = asset_id_type(); optional < uint16_t > maximum_son_count = GRAPHENE_DEFAULT_MAX_SONS; ///< maximum number of active SONS - optional < asset_id_type > hbd_asset = asset_id_type(); - optional < asset_id_type > hive_asset = asset_id_type(); }; struct chain_parameters @@ -214,12 +212,6 @@ namespace graphene { namespace chain { inline uint16_t maximum_son_count()const { return extensions.value.maximum_son_count.valid() ? *extensions.value.maximum_son_count : GRAPHENE_DEFAULT_MAX_SONS; } - inline asset_id_type hbd_asset() const { - return extensions.value.hbd_asset.valid() ? *extensions.value.hbd_asset : asset_id_type(); - } - inline asset_id_type hive_asset() const { - return extensions.value.hive_asset.valid() ? *extensions.value.hive_asset : asset_id_type(); - } private: static void safe_copy(chain_parameters& to, const chain_parameters& from); }; @@ -255,8 +247,6 @@ FC_REFLECT( graphene::chain::parameter_extension, (son_account) (btc_asset) (maximum_son_count) - (hbd_asset) - (hive_asset) ) FC_REFLECT( graphene::chain::chain_parameters, diff --git a/libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp b/libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp deleted file mode 100644 index 0c8ea855..00000000 --- a/libraries/chain/include/graphene/chain/protocol/nft_lottery.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#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 1802623f..4facf51a 100644 --- a/libraries/chain/include/graphene/chain/protocol/nft_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/nft_ops.hpp @@ -4,29 +4,6 @@ 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 @@ -46,10 +23,6 @@ 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; } @@ -160,9 +133,6 @@ 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) ) @@ -170,7 +140,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) (max_supply) (lottery_options) (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) (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 83d347ab..1a1222a5 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -50,14 +50,12 @@ #include #include #include -#include #include #include #include #include #include #include -#include namespace graphene { namespace chain { @@ -186,11 +184,7 @@ namespace graphene { namespace chain { sidechain_transaction_create_operation, sidechain_transaction_sign_operation, sidechain_transaction_send_operation, - sidechain_transaction_settle_operation, - nft_lottery_token_purchase_operation, - nft_lottery_reward_operation, - nft_lottery_end_operation, - random_number_store_operation + sidechain_transaction_settle_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 deleted file mode 100644 index 3dbe487f..00000000 --- a/libraries/chain/include/graphene/chain/protocol/random_number.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#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 321b08d9..56a4bb1c 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -183,7 +183,6 @@ 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 }; @@ -215,8 +214,7 @@ 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_nft_lottery_balance_object_type + impl_son_schedule_object_type }; //typedef fc::unsigned_int object_id_type; @@ -260,7 +258,6 @@ 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; @@ -300,7 +297,6 @@ 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; @@ -325,7 +321,6 @@ 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; @@ -357,7 +352,6 @@ 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; @@ -502,7 +496,6 @@ 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, @@ -533,7 +526,6 @@ 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 ) @@ -583,7 +575,6 @@ 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 ) @@ -591,7 +582,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 deleted file mode 100644 index a26b9f3e..00000000 --- a/libraries/chain/include/graphene/chain/random_number_evaluator.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#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 deleted file mode 100644 index 3613d7a1..00000000 --- a/libraries/chain/include/graphene/chain/random_number_object.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#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 7e2e8c7c..21cf492f 100644 --- a/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp +++ b/libraries/chain/include/graphene/chain/rbac_hardfork_visitor.hpp @@ -57,9 +57,6 @@ 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_defs.hpp b/libraries/chain/include/graphene/chain/sidechain_defs.hpp index 7f986f96..6bbc8b5c 100644 --- a/libraries/chain/include/graphene/chain/sidechain_defs.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_defs.hpp @@ -9,8 +9,7 @@ enum class sidechain_type { bitcoin, ethereum, eos, - peerplays, - hive + peerplays }; } } @@ -20,5 +19,4 @@ FC_REFLECT_ENUM(graphene::chain::sidechain_type, (bitcoin) (ethereum) (eos) - (hive) (peerplays) ) diff --git a/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp b/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp index 30a0dd5e..e9011ffb 100644 --- a/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_transaction_object.hpp @@ -26,8 +26,7 @@ namespace graphene { namespace chain { static const uint8_t space_id = protocol_ids; static const uint8_t type_id = sidechain_transaction_object_type; - time_point_sec timestamp; - sidechain_type sidechain = sidechain_type::unknown; + sidechain_type sidechain; object_id_type object_id; std::string transaction; std::vector signers; @@ -38,7 +37,7 @@ namespace graphene { namespace chain { uint32_t current_weight = 0; uint32_t threshold = 0; - sidechain_transaction_status status = sidechain_transaction_status::invalid; + sidechain_transaction_status status; }; struct by_object_id; @@ -71,7 +70,6 @@ FC_REFLECT_ENUM( graphene::chain::sidechain_transaction_status, (settled) ) FC_REFLECT_DERIVED( graphene::chain::sidechain_transaction_object, (graphene::db::object ), - (timestamp) (sidechain) (object_id) (transaction) diff --git a/libraries/chain/include/graphene/chain/son_object.hpp b/libraries/chain/include/graphene/chain/son_object.hpp index d0b74e79..53072515 100644 --- a/libraries/chain/include/graphene/chain/son_object.hpp +++ b/libraries/chain/include/graphene/chain/son_object.hpp @@ -31,9 +31,9 @@ namespace graphene { namespace chain { son_id_type owner; // Lifetime total transactions signed - flat_map total_txs_signed; + uint64_t total_txs_signed = 0; // Transactions signed since the last son payouts - flat_map txs_signed; + uint64_t txs_signed = 0; // Total Voted Active time i.e. duration selected as part of voted active SONs uint64_t total_voted_time = 0; // Total Downtime barring the current down time in seconds, used for stats to present to user @@ -47,9 +47,9 @@ namespace graphene { namespace chain { // Deregistered Timestamp fc::time_point_sec deregistered_timestamp; // Total sidechain transactions reported by SON network while SON was active - flat_map total_sidechain_txs_reported; + uint64_t total_sidechain_txs_reported = 0; // Sidechain transactions reported by this SON - flat_map sidechain_txs_reported; + uint64_t sidechain_txs_reported = 0; }; /** @@ -76,7 +76,6 @@ namespace graphene { namespace chain { void pay_son_fee(share_type pay, database& db); bool has_valid_config()const; - bool has_valid_config(time_point_sec head_block_time)const; }; struct by_account; diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 998950bf..1e87246e 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -200,20 +200,6 @@ 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< @@ -224,9 +210,11 @@ namespace graphene { namespace chain { ordered_non_unique< tag, composite_key< vesting_balance_object, - by_asset_balance_helper_asset_id, + member_offset, member, - by_asset_balance_helper_asset_amount + member_offset + //member + //member_offset >, composite_key_compare< std::less< asset_id_type >, diff --git a/libraries/chain/index.cpp b/libraries/chain/index.cpp new file mode 100644 index 00000000..41a469b2 --- /dev/null +++ b/libraries/chain/index.cpp @@ -0,0 +1,43 @@ +/* + * 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 eedbd5cc..f7f007ff 100644 --- a/libraries/chain/nft_evaluator.cpp +++ b/libraries/chain/nft_evaluator.cpp @@ -24,26 +24,6 @@ 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) ) } @@ -59,26 +39,6 @@ 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) ) } @@ -150,7 +110,6 @@ 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 deleted file mode 100644 index 794616cf..00000000 --- a/libraries/chain/nft_lottery_evaluator.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#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 deleted file mode 100644 index f5e9f674..00000000 --- a/libraries/chain/nft_lottery_object.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#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 ac8ef601..38521284 100644 --- a/libraries/chain/proposal_evaluator.cpp +++ b/libraries/chain/proposal_evaluator.cpp @@ -219,18 +219,6 @@ 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 new file mode 100644 index 00000000..1f35cf37 --- /dev/null +++ b/libraries/chain/protocol/competitor.cpp @@ -0,0 +1,35 @@ +/* + * 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/memo.cpp b/libraries/chain/protocol/memo.cpp index 1602ae77..afa0b486 100644 --- a/libraries/chain/protocol/memo.cpp +++ b/libraries/chain/protocol/memo.cpp @@ -30,7 +30,7 @@ namespace graphene { namespace chain { void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::public_key& pub, const string& msg, uint64_t custom_nonce) { - if( priv != fc::ecc::private_key() && pub.valid() ) + if( priv != fc::ecc::private_key() && public_key_type(pub) != public_key_type() ) { from = priv.get_public_key(); to = pub; @@ -57,7 +57,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub string memo_data::get_message(const fc::ecc::private_key& priv, const fc::ecc::public_key& pub)const { - if( from != public_key_type() && pub.valid() ) + if( from != public_key_type() ) { auto secret = priv.get_shared_secret(pub); auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str()); diff --git a/libraries/chain/protocol/nft.cpp b/libraries/chain/protocol/nft.cpp index ca7fe816..4a66f330 100644 --- a/libraries/chain/protocol/nft.cpp +++ b/libraries/chain/protocol/nft.cpp @@ -45,10 +45,6 @@ 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 deleted file mode 100644 index 16454962..00000000 --- a/libraries/chain/protocol/nft_lottery.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#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 deleted file mode 100644 index acfab042..00000000 --- a/libraries/chain/random_number_evaluator.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#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/sidechain_address_evaluator.cpp b/libraries/chain/sidechain_address_evaluator.cpp index 625ef2f0..ae802627 100644 --- a/libraries/chain/sidechain_address_evaluator.cpp +++ b/libraries/chain/sidechain_address_evaluator.cpp @@ -9,9 +9,7 @@ namespace graphene { namespace chain { void_result add_sidechain_address_evaluator::do_evaluate(const sidechain_address_add_operation& op) { try{ - if (op.sidechain == sidechain_type::bitcoin) { - FC_ASSERT( op.deposit_public_key.length() > 0 && op.deposit_address.length() == 0 && op.deposit_address_data.length() == 0, "ser should add a valid deposit public key and a null deposit address (Bitcoin only)"); - } + FC_ASSERT( op.deposit_public_key.length() > 0 && op.deposit_address.length() == 0 && op.deposit_address_data.length() == 0, "User should add a valid deposit public key and a null deposit address"); const auto& sdpke_idx = db().get_index_type().indices().get(); FC_ASSERT( sdpke_idx.find(boost::make_tuple(op.sidechain, op.deposit_public_key, time_point_sec::maximum())) == sdpke_idx.end(), "An active deposit key already exists" ); return void_result(); @@ -33,8 +31,8 @@ object_id_type add_sidechain_address_evaluator::do_apply(const sidechain_address obj.sidechain_address_account = op.sidechain_address_account; obj.sidechain = op.sidechain; obj.deposit_public_key = op.deposit_public_key; - obj.deposit_address = op.deposit_address; - obj.deposit_address_data = op.deposit_address_data; + obj.deposit_address = ""; + obj.deposit_address_data = ""; obj.withdraw_public_key = op.withdraw_public_key; obj.withdraw_address = op.withdraw_address; obj.valid_from = db().head_block_time(); diff --git a/libraries/chain/sidechain_transaction_evaluator.cpp b/libraries/chain/sidechain_transaction_evaluator.cpp index ba256199..12bf2f42 100644 --- a/libraries/chain/sidechain_transaction_evaluator.cpp +++ b/libraries/chain/sidechain_transaction_evaluator.cpp @@ -28,7 +28,6 @@ void_result sidechain_transaction_create_evaluator::do_evaluate(const sidechain_ object_id_type sidechain_transaction_create_evaluator::do_apply(const sidechain_transaction_create_operation &op) { try { const auto &new_sidechain_transaction_object = db().create([&](sidechain_transaction_object &sto) { - sto.timestamp = db().head_block_time(); sto.sidechain = op.sidechain; sto.object_id = op.object_id; sto.transaction = op.transaction; @@ -98,15 +97,7 @@ object_id_type sidechain_transaction_sign_evaluator::do_apply(const sidechain_tr }); db().modify(son_obj->statistics(db()), [&](son_statistics_object& sso) { - if (sso.total_txs_signed.find(sto_obj->sidechain) == sso.total_txs_signed.end()) { - sso.total_txs_signed[sto_obj->sidechain] = 0; - } - sso.total_txs_signed[sto_obj->sidechain] += 1; - - if (sso.txs_signed.find(sto_obj->sidechain) == sso.txs_signed.end()) { - sso.txs_signed[sto_obj->sidechain] = 0; - } - sso.txs_signed[sto_obj->sidechain] += 1; + sso.txs_signed += 1; }); return op.sidechain_transaction_id; diff --git a/libraries/chain/son_object.cpp b/libraries/chain/son_object.cpp index ae61f682..bf54c833 100644 --- a/libraries/chain/son_object.cpp +++ b/libraries/chain/son_object.cpp @@ -12,17 +12,4 @@ namespace graphene { namespace chain { (sidechain_public_keys.find( sidechain_type::bitcoin ) != sidechain_public_keys.end()) && (sidechain_public_keys.at(sidechain_type::bitcoin).length() > 0)); } - - bool son_object::has_valid_config(time_point_sec head_block_time)const { - bool retval = has_valid_config(); - - if (head_block_time >= HARDFORK_SON_FOR_HIVE_TIME) { - retval = retval && - (sidechain_public_keys.find( sidechain_type::hive ) != sidechain_public_keys.end()) && - (sidechain_public_keys.at(sidechain_type::hive).length() > 0); - } - - return retval; - } - }} diff --git a/libraries/chain/son_wallet_deposit_evaluator.cpp b/libraries/chain/son_wallet_deposit_evaluator.cpp index f9620282..24a87e47 100644 --- a/libraries/chain/son_wallet_deposit_evaluator.cpp +++ b/libraries/chain/son_wallet_deposit_evaluator.cpp @@ -84,16 +84,9 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de auto stats_itr = db().get_index_type().indices().get().find(si.son_id); db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) { - if (sso.total_sidechain_txs_reported.find(op.sidechain) == sso.total_sidechain_txs_reported.end()) { - sso.total_sidechain_txs_reported[op.sidechain] = 0; - } - sso.total_sidechain_txs_reported[op.sidechain] += 1; - + sso.total_sidechain_txs_reported = sso.total_sidechain_txs_reported + 1; if (si.son_id == op.son_id) { - if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) { - sso.sidechain_txs_reported[op.sidechain] = 0; - } - sso.sidechain_txs_reported[op.sidechain] += 1; + sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; } }); } @@ -129,10 +122,7 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de }); auto stats_itr = db().get_index_type().indices().get().find(op.son_id); db().modify(*stats_itr, [&op](son_statistics_object &sso) { - if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) { - sso.sidechain_txs_reported[op.sidechain] = 0; - } - sso.sidechain_txs_reported[op.sidechain] += 1; + sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; }); return (*itr).id; } diff --git a/libraries/chain/son_wallet_withdraw_evaluator.cpp b/libraries/chain/son_wallet_withdraw_evaluator.cpp index 2110e49d..bf6adaf9 100644 --- a/libraries/chain/son_wallet_withdraw_evaluator.cpp +++ b/libraries/chain/son_wallet_withdraw_evaluator.cpp @@ -82,16 +82,9 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w auto stats_itr = db().get_index_type().indices().get().find(si.son_id); db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) { - if (sso.total_sidechain_txs_reported.find(op.sidechain) == sso.total_sidechain_txs_reported.end()) { - sso.total_sidechain_txs_reported[op.sidechain] = 0; - } - sso.total_sidechain_txs_reported[op.sidechain] += 1; - + sso.total_sidechain_txs_reported = sso.total_sidechain_txs_reported + 1; if (si.son_id == op.son_id) { - if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) { - sso.sidechain_txs_reported[op.sidechain] = 0; - } - sso.sidechain_txs_reported[op.sidechain] += 1; + sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; } }); } @@ -127,10 +120,7 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w }); auto stats_itr = db().get_index_type().indices().get().find(op.son_id); db().modify(*stats_itr, [&op](son_statistics_object &sso) { - if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) { - sso.sidechain_txs_reported[op.sidechain] = 0; - } - sso.sidechain_txs_reported[op.sidechain] += 1; + sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; }); return (*itr).id; } diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp index 056652e5..ad64b34f 100644 --- a/libraries/chain/tournament_object.cpp +++ b/libraries/chain/tournament_object.cpp @@ -605,9 +605,8 @@ namespace graphene { namespace chain { return; // We shouldn't be here if the final match is complete - 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) + assert(last_complete_round != num_rounds - 1); + if (last_complete_round == num_rounds - 1) return; if (first_incomplete_match_was_waiting) diff --git a/libraries/chain/transaction_object.cpp b/libraries/chain/transaction_object.cpp new file mode 100644 index 00000000..fb4f75df --- /dev/null +++ b/libraries/chain/transaction_object.cpp @@ -0,0 +1,95 @@ +/* + * 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 4b727372..9f104869 100644 --- a/libraries/db/include/graphene/db/undo_database.hpp +++ b/libraries/db/include/graphene/db/undo_database.hpp @@ -59,7 +59,17 @@ namespace graphene { namespace db { { mv._apply_undo = false; } - ~session(); + ~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(); + } 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 bffd761d..c5f2ef65 100644 --- a/libraries/db/undo_database.cpp +++ b/libraries/db/undo_database.cpp @@ -30,18 +30,6 @@ 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 75589999..68de4b00 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 ) +target_link_libraries( graphene_egenesis_none graphene_chain fc ) 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 PRIVATE graphene_app graphene_egenesis_none ) +target_link_libraries( embed_genesis graphene_chain graphene_app graphene_egenesis_none fc ) 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 ) -target_link_libraries( graphene_egenesis_full graphene_chain ) +target_link_libraries( graphene_egenesis_brief graphene_chain fc ) +target_link_libraries( graphene_egenesis_full graphene_chain fc ) target_include_directories( graphene_egenesis_brief PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/net/CMakeLists.txt b/libraries/net/CMakeLists.txt index 1cc71728..955012e4 100644 --- a/libraries/net/CMakeLists.txt +++ b/libraries/net/CMakeLists.txt @@ -10,8 +10,12 @@ set(SOURCES node.cpp add_library( graphene_net ${SOURCES} ${HEADERS} ) -target_link_libraries( graphene_net graphene_chain ) -target_include_directories( graphene_net PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) +target_link_libraries( graphene_net + PUBLIC fc graphene_db ) +target_include_directories( graphene_net + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../chain/include" "${CMAKE_CURRENT_BINARY_DIR}/../chain/include" +) if(MSVC) set_source_files_properties( node.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 3222da08..14e32306 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -2375,7 +2375,6 @@ 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 @@ -3415,7 +3414,6 @@ 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 20497629..d2a5be16 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( bookie ) -add_subdirectory( debug_witness ) -add_subdirectory( delayed_node ) add_subdirectory( elasticsearch ) -add_subdirectory( es_objects ) +add_subdirectory( market_history ) +add_subdirectory( delayed_node ) +add_subdirectory( bookie ) add_subdirectory( generate_genesis ) add_subdirectory( generate_uia_sharedrop_genesis ) -add_subdirectory( market_history ) -add_subdirectory( peerplays_sidechain ) +add_subdirectory( debug_witness ) add_subdirectory( snapshot ) -add_subdirectory( witness ) +add_subdirectory( peerplays_sidechain ) +add_subdirectory( es_objects ) diff --git a/libraries/plugins/account_history/CMakeLists.txt b/libraries/plugins/account_history/CMakeLists.txt index 4a40fba8..4af81abb 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 PRIVATE graphene_plugin ) +target_link_libraries( graphene_account_history graphene_chain graphene_app ) 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 b337409e..3c2747c2 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 PRIVATE graphene_plugin ) +target_link_libraries( graphene_accounts_list graphene_chain graphene_app ) 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 60b2d6e2..fec2544c 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 PRIVATE graphene_plugin graphene_account_history ) +target_link_libraries( graphene_affiliate_stats graphene_chain graphene_app ) 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 d7c6d4c0..12d84e3c 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 PRIVATE graphene_plugin ) +target_link_libraries( graphene_bookie graphene_chain graphene_app ) 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 ac7d7fc9..f0fcb7fb 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 PRIVATE graphene_plugin ) +target_link_libraries( graphene_debug_witness graphene_chain graphene_app ) 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 d481eb84..63dd73e5 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 PRIVATE graphene_plugin graphene_accounts_list graphene_affiliate_stats graphene_bookie graphene_debug_witness graphene_elasticsearch graphene_market_history ) +target_link_libraries( graphene_delayed_node graphene_chain graphene_app ) 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 928d2e3c..f4815576 100644 --- a/libraries/plugins/elasticsearch/CMakeLists.txt +++ b/libraries/plugins/elasticsearch/CMakeLists.txt @@ -4,21 +4,13 @@ add_library( graphene_elasticsearch elasticsearch_plugin.cpp ) -find_curl() +target_link_libraries( graphene_elasticsearch graphene_chain graphene_app curl ) +target_include_directories( graphene_elasticsearch + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) -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 8777c06d..dc167b05 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 = true; + bool _elasticsearch_operation_object = false; uint32_t _elasticsearch_start_es_after_block = 0; - bool _elasticsearch_operation_string = false; + bool _elasticsearch_operation_string = true; mode _elasticsearch_mode = mode::only_save; CURL *curl; // curl handler vector bulk_lines; // vector of op lines @@ -75,19 +75,20 @@ 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(uint32_t trx_in_block, const signed_block& b); + void doBlock(const optional & oho, const signed_block& b); void doVisitor(const optional & oho); void checkState(const fc::time_point_sec& block_time); - void cleanObjects(const account_transaction_history_id_type& ath, const account_id_type& account_id); + void cleanObjects(const account_transaction_history_object& ath, 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(); @@ -147,7 +148,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->trx_in_block, b); + doBlock(oho, b); if(_elasticsearch_visitor) doVisitor(oho); @@ -173,11 +174,7 @@ 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 @@ -188,33 +185,23 @@ 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) { - if((fc::time_point::now() - block_time) < fc::seconds(30)) + fc::time_point current_time(fc::time_point::now()); + if(((current_time - block_time) < fc::seconds(30)) || (current_time - last_sync > fc::seconds(60))) { limit_documents = _elasticsearch_bulk_sync; is_sync = true; + last_sync = current_time; } else { @@ -245,11 +232,11 @@ void elasticsearch_plugin_impl::doOperationHistory(const optional op); } -void elasticsearch_plugin_impl::doBlock(uint32_t trx_in_block, const signed_block& b) +void elasticsearch_plugin_impl::doBlock(const optional & oho, const signed_block& b) { std::string trx_id = ""; - if(trx_in_block < b.transactions.size()) - trx_id = b.transactions[trx_in_block].id().str(); + if(oho->trx_in_block < b.transactions.size()) + trx_id = b.transactions[oho->trx_in_block].id().str(); bs.block_num = b.block_num(); bs.block_time = b.timestamp; bs.trx_id = trx_id; @@ -257,41 +244,23 @@ void elasticsearch_plugin_impl::doBlock(uint32_t trx_in_block, const signed_bloc void elasticsearch_plugin_impl::doVisitor(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; } @@ -307,22 +276,13 @@ bool elasticsearch_plugin_impl::add_elasticsearch( const account_id_type account createBulkLine(ath); prepareBulk(ath.id); } - cleanObjects(ath.id, account_id); + cleanObjects(ath, 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(); } @@ -330,16 +290,15 @@ 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 &stats_obj = db.get_account_stats_by_owner(account_id); - - return stats_obj; + const auto &acct = db.get(account_id); + return acct.statistics(db); } 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(); @@ -381,21 +340,19 @@ 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) + "." - + 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(); + 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()); } -void elasticsearch_plugin_impl::cleanObjects(const account_transaction_history_id_type& ath_id, const account_id_type& account_id) +void elasticsearch_plugin_impl::cleanObjects(const account_transaction_history_object& ath, 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; @@ -420,12 +377,9 @@ void elasticsearch_plugin_impl::cleanObjects(const account_transaction_history_i void elasticsearch_plugin_impl::populateESstruct() { es.curl = curl; - es.bulk_lines = std::move(bulk_lines); + es.bulk_lines = 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 @@ -467,11 +421,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(true)") + "Save operation as object(false)") ("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(false)") + "Save operation as string. Needed to serve history api calls(true)") ("elasticsearch-mode", boost::program_options::value(), "Mode of operation: only_save(0), only_query(1), all(2) - Default: 0") ; @@ -513,18 +467,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(graphene::chain::plugin_exception, "Elasticsearch mode not valid"); + FC_THROW_EXCEPTION(fc::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(graphene::chain::plugin_exception, + FC_THROW_EXCEPTION(fc::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(graphene::chain::plugin_exception, + FC_THROW_EXCEPTION(fc::exception, "Error populating ES database, we are going to keep trying."); }); } @@ -609,12 +563,13 @@ 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"]; + const auto hits = variant_response["hits"]["total"]["value"]; 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 { @@ -77,16 +61,6 @@ 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 @@ -105,6 +79,7 @@ class es_objects_plugin_impl bool es_objects_plugin_impl::genesis() { + ilog("elasticsearch OBJECTS: inserting data from genesis"); graphene::chain::database &db = _self.database(); @@ -137,142 +112,13 @@ 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(graphene::chain::plugin_exception, "Error inserting genesis data."); + FC_THROW_EXCEPTION(fc::exception, "Error inserting genesis data."); else bulk.clear(); @@ -351,150 +197,6 @@ 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"); - } } } @@ -594,39 +296,52 @@ 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(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)") + ("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)") ; 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(); } @@ -657,30 +372,6 @@ 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(); } @@ -690,37 +381,6 @@ 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() @@ -736,4 +396,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 acc24202..45ad5719 100644 --- a/libraries/plugins/generate_genesis/CMakeLists.txt +++ b/libraries/plugins/generate_genesis/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_generate_genesis generate_genesis.cpp ) -target_link_libraries( graphene_generate_genesis PRIVATE graphene_plugin ) +target_link_libraries( graphene_generate_genesis graphene_chain graphene_app graphene_time ) 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 737e7614..d2a50ab6 100644 --- a/libraries/plugins/generate_uia_sharedrop_genesis/CMakeLists.txt +++ b/libraries/plugins/generate_uia_sharedrop_genesis/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_generate_uia_sharedrop_genesis generate_uia_sharedrop_genesis.cpp ) -target_link_libraries( graphene_generate_uia_sharedrop_genesis PRIVATE graphene_plugin ) +target_link_libraries( graphene_generate_uia_sharedrop_genesis graphene_chain graphene_app graphene_time ) 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 new file mode 100644 index 00000000..ef1ae04c --- /dev/null +++ b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp @@ -0,0 +1,303 @@ +/* + * 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 8100de28..47410d74 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 PRIVATE graphene_plugin ) +target_link_libraries( graphene_market_history graphene_chain graphene_app ) 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 bb74df29..3e37b6fe 100755 --- a/libraries/plugins/peerplays_sidechain/CMakeLists.txt +++ b/libraries/plugins/peerplays_sidechain/CMakeLists.txt @@ -5,7 +5,6 @@ add_library( peerplays_sidechain sidechain_net_manager.cpp sidechain_net_handler.cpp sidechain_net_handler_bitcoin.cpp - sidechain_net_handler_hive.cpp sidechain_net_handler_peerplays.cpp bitcoin/bech32.cpp bitcoin/bitcoin_address.cpp @@ -14,12 +13,6 @@ add_library( peerplays_sidechain bitcoin/segwit_addr.cpp bitcoin/utils.cpp bitcoin/sign_bitcoin_transaction.cpp - common/rpc_client.cpp - common/utils.cpp - hive/asset.cpp - hive/operations.cpp - hive/transaction.cpp - hive/types.cpp ) if (ENABLE_DEV_FEATURES) @@ -43,7 +36,7 @@ endif() unset(ENABLE_PEERPLAYS_ASSET_DEPOSITS) unset(ENABLE_PEERPLAYS_ASSET_DEPOSITS CACHE) -target_link_libraries( peerplays_sidechain PRIVATE curl graphene_plugin zmq ) +target_link_libraries( peerplays_sidechain graphene_chain graphene_app fc 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 50c02964..07078147 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp @@ -1,4 +1,3 @@ -#include #include #include diff --git a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp index fac29f5a..b4fde6dc 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_transaction.cpp @@ -1,5 +1,4 @@ #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 afad2093..edb45c5b 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin/sign_bitcoin_transaction.cpp @@ -1,7 +1,4 @@ #include - -#include - #include namespace graphene { namespace peerplays_sidechain { namespace bitcoin { diff --git a/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp b/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp deleted file mode 100644 index ce4081c2..00000000 --- a/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#include - -#include -#include - -#include -#include - -#include - -#include -#include - -namespace graphene { namespace peerplays_sidechain { - -rpc_client::rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls) : - ip(_ip), - port(_port), - user(_user), - password(_password), - debug_rpc_calls(_debug_rpc_calls), - request_id(0) { - authorization.key = "Authorization"; - authorization.val = "Basic " + fc::base64_encode(user + ":" + password); -} - -std::string rpc_client::retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx) { - std::stringstream ss(reply_str); - boost::property_tree::ptree json; - boost::property_tree::read_json(ss, json); - if (json.find("result") == json.not_found()) { - return ""; - } - auto json_result = json.get_child("result"); - if (json_result.find(array_path) == json_result.not_found()) { - return ""; - } - - boost::property_tree::ptree array_ptree = json_result; - if (!array_path.empty()) { - array_ptree = json_result.get_child(array_path); - } - uint32_t array_el_idx = -1; - for (const auto &array_el : array_ptree) { - array_el_idx = array_el_idx + 1; - if (array_el_idx == idx) { - std::stringstream ss_res; - boost::property_tree::json_parser::write_json(ss_res, array_el.second); - return ss_res.str(); - } - } - - return ""; -} - -std::string rpc_client::retrieve_value_from_reply(std::string reply_str, std::string value_path) { - std::stringstream ss(reply_str); - boost::property_tree::ptree json; - boost::property_tree::read_json(ss, json); - if (json.find("result") == json.not_found()) { - return ""; - } - auto json_result = json.get_child("result"); - if (json_result.find(value_path) == json_result.not_found()) { - return ""; - } - return json_result.get(value_path); -} - -std::string rpc_client::send_post_request(std::string method, std::string params, bool show_log) { - std::stringstream body; - - request_id = request_id + 1; - - body << "{ \"jsonrpc\": \"2.0\", \"id\": " << request_id << ", \"method\": \"" << method << "\""; - - if (!params.empty()) { - body << ", \"params\": " << params; - } - - body << " }"; - - const auto reply = send_post_request(body.str(), show_log); - - if (reply.body.empty()) { - wlog("RPC call ${function} failed", ("function", __FUNCTION__)); - return ""; - } - - std::stringstream ss(std::string(reply.body.begin(), reply.body.end())); - boost::property_tree::ptree json; - boost::property_tree::read_json(ss, json); - - if (reply.status == 200) { - return ss.str(); - } - - if (json.count("error") && !json.get_child("error").empty()) { - wlog("RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body.str())("msg", ss.str())); - } - return ""; -} - -//fc::http::reply rpc_client::send_post_request(std::string body, bool show_log) { -// fc::http::connection conn; -// conn.connect_to(fc::ip::endpoint(fc::ip::address(ip), port)); -// -// std::string url = "http://" + ip + ":" + std::to_string(port); -// -// //if (wallet.length() > 0) { -// // url = url + "/wallet/" + wallet; -// //} -// -// fc::http::reply reply = conn.request("POST", url, body, fc::http::headers{authorization}); -// -// if (show_log) { -// ilog("### Request URL: ${url}", ("url", url)); -// ilog("### Request: ${body}", ("body", body)); -// std::stringstream ss(std::string(reply.body.begin(), reply.body.end())); -// ilog("### Response: ${ss}", ("ss", ss.str())); -// } -// -// return reply; -//} - -static size_t write_callback(char *ptr, size_t size, size_t nmemb, rpc_reply *reply) { - size_t retval = 0; - if (reply != nullptr) { - reply->body.append(ptr, size * nmemb); - retval = size * nmemb; - } - return retval; -} - -rpc_reply rpc_client::send_post_request(std::string body, bool show_log) { - - struct curl_slist *headers = nullptr; - headers = curl_slist_append(headers, "Accept: application/json"); - headers = curl_slist_append(headers, "Content-Type: application/json"); - headers = curl_slist_append(headers, "charset: utf-8"); - - CURL *curl = curl_easy_init(); - if (ip.find("https://", 0) != 0) { - curl_easy_setopt(curl, CURLOPT_URL, ip.c_str()); - curl_easy_setopt(curl, CURLOPT_PORT, port); - } else { - std::string full_address = ip + ":" + std::to_string(port); - curl_easy_setopt(curl, CURLOPT_URL, full_address.c_str()); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false); - } - if (!user.empty()) { - curl_easy_setopt(curl, CURLOPT_USERNAME, user.c_str()); - curl_easy_setopt(curl, CURLOPT_PASSWORD, password.c_str()); - } - - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str()); - - //curl_easy_setopt(curl, CURLOPT_VERBOSE, true); - - rpc_reply reply; - - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &reply); - - curl_easy_perform(curl); - - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &reply.status); - - curl_easy_cleanup(curl); - curl_slist_free_all(headers); - - if (show_log) { - std::string url = ip + ":" + std::to_string(port); - ilog("### Request URL: ${url}", ("url", url)); - ilog("### Request: ${body}", ("body", body)); - std::stringstream ss(std::string(reply.body.begin(), reply.body.end())); - ilog("### Response: ${ss}", ("ss", ss.str())); - } - - return reply; -} - -}} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/common/utils.cpp b/libraries/plugins/peerplays_sidechain/common/utils.cpp deleted file mode 100644 index 4491487f..00000000 --- a/libraries/plugins/peerplays_sidechain/common/utils.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -std::string object_id_to_string(graphene::chain::object_id_type id) { - std::string object_id = fc::to_string(id.space()) + "." + - fc::to_string(id.type()) + "." + - fc::to_string(id.instance()); - return object_id; -} diff --git a/libraries/plugins/peerplays_sidechain/hive/asset.cpp b/libraries/plugins/peerplays_sidechain/hive/asset.cpp deleted file mode 100644 index 7417107f..00000000 --- a/libraries/plugins/peerplays_sidechain/hive/asset.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include - -#include - -#include -#include - -#define ASSET_AMOUNT_KEY "amount" -#define ASSET_PRECISION_KEY "precision" -#define ASSET_NAI_KEY "nai" - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -uint64_t asset::hbd_symbol_ser = HBD_SYMBOL_SER; -uint64_t asset::hive_symbol_ser = HIVE_SYMBOL_SER; - -}}} // namespace graphene::peerplays_sidechain::hive - -namespace fc { - -void to_variant(const graphene::peerplays_sidechain::hive::asset &var, fc::variant &vo, uint32_t max_depth) { - try { - if (var.symbol == HBD_SYMBOL_SER) { - variant v = mutable_variant_object(ASSET_AMOUNT_KEY, boost::lexical_cast(var.amount.value))(ASSET_PRECISION_KEY, uint64_t(HBD_PRECISION))(ASSET_NAI_KEY, HBD_NAI); - vo = v; - } - if (var.symbol == HIVE_SYMBOL_SER) { - variant v = mutable_variant_object(ASSET_AMOUNT_KEY, boost::lexical_cast(var.amount.value))(ASSET_PRECISION_KEY, uint64_t(HIVE_PRECISION))(ASSET_NAI_KEY, HIVE_NAI); - vo = v; - } - if (var.symbol == TBD_SYMBOL_SER) { - variant v = mutable_variant_object(ASSET_AMOUNT_KEY, boost::lexical_cast(var.amount.value))(ASSET_PRECISION_KEY, uint64_t(TBD_PRECISION))(ASSET_NAI_KEY, TBD_NAI); - vo = v; - } - if (var.symbol == TESTS_SYMBOL_SER) { - variant v = mutable_variant_object(ASSET_AMOUNT_KEY, boost::lexical_cast(var.amount.value))(ASSET_PRECISION_KEY, uint64_t(TESTS_PRECISION))(ASSET_NAI_KEY, TESTS_NAI); - vo = v; - } - } - FC_CAPTURE_AND_RETHROW() -} - -void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::asset &vo, uint32_t max_depth) { - try { - FC_ASSERT(var.is_object(), "Asset has to be treated as object."); - - const auto &v_object = var.get_object(); - - FC_ASSERT(v_object.contains(ASSET_AMOUNT_KEY), "Amount field doesn't exist."); - FC_ASSERT(v_object[ASSET_AMOUNT_KEY].is_string(), "Expected a string type for value '${key}'.", ("key", ASSET_AMOUNT_KEY)); - vo.amount = boost::lexical_cast(v_object[ASSET_AMOUNT_KEY].as(max_depth)); - FC_ASSERT(vo.amount >= 0, "Asset amount cannot be negative"); - - FC_ASSERT(v_object.contains(ASSET_PRECISION_KEY), "Precision field doesn't exist."); - FC_ASSERT(v_object[ASSET_PRECISION_KEY].is_uint64(), "Expected an unsigned integer type for value '${key}'.", ("key", ASSET_PRECISION_KEY)); - - FC_ASSERT(v_object.contains(ASSET_NAI_KEY), "NAI field doesn't exist."); - FC_ASSERT(v_object[ASSET_NAI_KEY].is_string(), "Expected a string type for value '${key}'.", ("key", ASSET_NAI_KEY)); - - if (v_object[ASSET_NAI_KEY].as(max_depth) == HBD_NAI) { - vo.symbol = graphene::peerplays_sidechain::hive::asset::hbd_symbol_ser; - } - if (v_object[ASSET_NAI_KEY].as(max_depth) == HIVE_NAI) { - vo.symbol = graphene::peerplays_sidechain::hive::asset::hive_symbol_ser; - } - } - FC_CAPTURE_AND_RETHROW() -} -} // namespace fc diff --git a/libraries/plugins/peerplays_sidechain/hive/operations.cpp b/libraries/plugins/peerplays_sidechain/hive/operations.cpp deleted file mode 100644 index b21b564e..00000000 --- a/libraries/plugins/peerplays_sidechain/hive/operations.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include - -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -}}} // namespace graphene::peerplays_sidechain::hive - -namespace fc { - -static std::string trim_typename_namespace(const std::string &name) { - auto start = name.find_last_of(':'); - start = (start == std::string::npos) ? 0 : start + 1; - return name.substr(start); -} - -struct from_static_variant_for_hive { - fc::variant &var; - from_static_variant_for_hive(fc::variant &dv) : - var(dv) { - } - - typedef void result_type; - template - void operator()(const T &v) const { - auto name = trim_typename_namespace(fc::get_typename::name()); - fc::variant value; - to_variant(v, value, 5); - var = mutable_variant_object("type", name).set("value", value); - } -}; - -struct to_static_variant_for_hive { - const fc::variant &var; - to_static_variant_for_hive(const fc::variant &dv) : - var(dv) { - } - - typedef void result_type; - template - void operator()(T &v) const { - from_variant(var, v, 5); - } -}; - -struct get_static_variant_name { - string &name; - get_static_variant_name(string &n) : - name(n) { - } - - typedef void result_type; - template - void operator()(T &v) const { - name = trim_typename_namespace(fc::get_typename::name()); - } -}; - -void to_variant(const graphene::peerplays_sidechain::hive::hive_operation &var, fc::variant &vo, uint32_t max_depth) { - var.visit(from_static_variant_for_hive(vo)); -} - -void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::hive_operation &vo, uint32_t max_depth) { - static std::map to_tag = []() { - std::map name_map; - for (int i = 0; i < graphene::peerplays_sidechain::hive::hive_operation::count(); ++i) { - graphene::peerplays_sidechain::hive::hive_operation tmp; - tmp.set_which(i); - string n; - tmp.visit(get_static_variant_name(n)); - name_map[n] = i; - } - return name_map; - }(); - - auto ar = var.get_array(); - if (ar.size() < 2) - return; - auto var_second = ar[1]; - - FC_ASSERT(var_second.is_object(), "Input data have to treated as object."); - auto v_object = var_second.get_object(); - - FC_ASSERT(v_object.contains("type"), "Type field doesn't exist."); - FC_ASSERT(v_object.contains("value"), "Value field doesn't exist."); - - int64_t which = -1; - - if (v_object["type"].is_integer()) { - which = v_object["type"].as_int64(); - } else { - auto itr = to_tag.find(v_object["type"].as_string()); - FC_ASSERT(itr != to_tag.end(), "Invalid object name: ${n}", ("n", v_object["type"])); - which = itr->second; - } - - vo.set_which(which); - vo.visit(fc::to_static_variant_for_hive(v_object["value"])); -} - -} // namespace fc diff --git a/libraries/plugins/peerplays_sidechain/hive/transaction.cpp b/libraries/plugins/peerplays_sidechain/hive/transaction.cpp deleted file mode 100644 index 3e4a59f5..00000000 --- a/libraries/plugins/peerplays_sidechain/hive/transaction.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include - -#include - -#include -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -digest_type transaction::digest() const { - digest_type::encoder enc; - fc::raw::pack(enc, *this); - return enc.result(); -} - -transaction_id_type transaction::id() const { - auto h = digest(); - transaction_id_type result; - memcpy(result._hash, h._hash, std::min(sizeof(result), sizeof(h))); - return result; -} - -digest_type transaction::sig_digest(const chain_id_type &chain_id) const { - digest_type::encoder enc; - fc::raw::pack(enc, chain_id); - fc::raw::pack(enc, *this); - return enc.result(); -} - -void transaction::set_expiration(fc::time_point_sec expiration_time) { - expiration = expiration_time; -} - -void transaction::set_reference_block(const block_id_type &reference_block) { - ref_block_num = fc::endian_reverse_u32(reference_block._hash[0]); - ref_block_prefix = reference_block._hash[1]; -} - -void signed_transaction::clear() { - operations.clear(); - signatures.clear(); -} - -const signature_type &signed_transaction::sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id) { - digest_type h = sig_digest(chain_id); - signatures.push_back(key.sign_compact(h, true)); - return signatures.back(); -} - -signature_type signed_transaction::sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id) const { - digest_type::encoder enc; - fc::raw::pack(enc, chain_id); - fc::raw::pack(enc, *this); - return key.sign_compact(enc.result(), true); -} - -}}} // namespace graphene::peerplays_sidechain::hive diff --git a/libraries/plugins/peerplays_sidechain/hive/types.cpp b/libraries/plugins/peerplays_sidechain/hive/types.cpp deleted file mode 100644 index 7a5506e7..00000000 --- a/libraries/plugins/peerplays_sidechain/hive/types.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include - -#include -#include -#include -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -std::string public_key_type::prefix = KEY_PREFIX_STM; - -public_key_type::public_key_type() : - key_data(){}; - -public_key_type::public_key_type(const fc::ecc::public_key_data &data) : - key_data(data){}; - -public_key_type::public_key_type(const fc::ecc::public_key &pubkey) : - key_data(pubkey){}; - -public_key_type::public_key_type(const std::string &base58str) { - const size_t prefix_len = prefix.size(); - FC_ASSERT(base58str.size() > prefix_len); - FC_ASSERT(base58str.substr(0, prefix_len) == prefix, "", ("base58str", base58str)); - auto bin = fc::from_base58(base58str.substr(prefix_len)); - auto bin_key = fc::raw::unpack(bin); - key_data = bin_key.data; - FC_ASSERT(fc::ripemd160::hash(key_data.data, key_data.size())._hash[0] == bin_key.check); -}; - -public_key_type::operator fc::ecc::public_key_data() const { - return key_data; -}; - -public_key_type::operator fc::ecc::public_key() const { - return fc::ecc::public_key(key_data); -}; - -public_key_type::operator std::string() const { - binary_key k; - k.data = key_data; - k.check = fc::ripemd160::hash(k.data.data, k.data.size())._hash[0]; - auto data = fc::raw::pack(k); - return prefix + fc::to_base58(data.data(), data.size()); -} - -bool operator==(const public_key_type &p1, const fc::ecc::public_key &p2) { - return p1.key_data == p2.serialize(); -} - -bool operator==(const public_key_type &p1, const public_key_type &p2) { - return p1.key_data == p2.key_data; -} - -bool operator!=(const public_key_type &p1, const public_key_type &p2) { - return p1.key_data != p2.key_data; -} - -}}} // namespace graphene::peerplays_sidechain::hive - -namespace fc { - -using namespace std; - -void to_variant(const graphene::peerplays_sidechain::hive::public_key_type &var, fc::variant &vo, uint32_t max_depth) { - vo = std::string(var); -} - -void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::public_key_type &vo, uint32_t max_depth) { - vo = graphene::peerplays_sidechain::hive::public_key_type(var.as_string()); -} - -} // namespace fc diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/rpc_client.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/rpc_client.hpp deleted file mode 100644 index f61bdb3f..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/rpc_client.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include -#include - -#include - -namespace graphene { namespace peerplays_sidechain { - -struct rpc_reply { - uint16_t status; - std::string body; -}; - -class rpc_client { -public: - rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls); - -protected: - std::string retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx); - std::string retrieve_value_from_reply(std::string reply_str, std::string value_path); - std::string send_post_request(std::string method, std::string params, bool show_log); - - std::string ip; - uint32_t port; - std::string user; - std::string password; - bool debug_rpc_calls; - - uint32_t request_id; - - fc::http::header authorization; - -private: - //fc::http::reply send_post_request(std::string body, bool show_log); - rpc_reply send_post_request(std::string body, bool show_log); -}; - -}} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp deleted file mode 100644 index 99c59019..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/common/utils.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -std::string object_id_to_string(graphene::chain::object_id_type id); diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/asset.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/asset.hpp deleted file mode 100644 index f0743741..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/asset.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -#define HBD_NAI "@@000000013" -#define HBD_PRECISION 3 -#define HBD_SYMBOL_U64 (uint64_t('S') | (uint64_t('B') << 8) | (uint64_t('D') << 16)) -#define HBD_SYMBOL_SER (uint64_t(3) | (HBD_SYMBOL_U64 << 8)) - -#define HIVE_NAI "@@000000021" -#define HIVE_PRECISION 3 -#define HIVE_SYMBOL_U64 (uint64_t('S') | (uint64_t('T') << 8) | (uint64_t('E') << 16) | (uint64_t('E') << 24) | (uint64_t('M') << 32)) -#define HIVE_SYMBOL_SER (uint64_t(3) | (HIVE_SYMBOL_U64 << 8)) - -#define TBD_NAI "@@000000013" -#define TBD_PRECISION 3 -#define TBD_SYMBOL_U64 (uint64_t('T') | (uint64_t('B') << 8) | (uint64_t('D') << 16)) -#define TBD_SYMBOL_SER (uint64_t(3) | (TBD_SYMBOL_U64 << 8)) - -#define TESTS_NAI "@@000000021" -#define TESTS_PRECISION 3 -#define TESTS_SYMBOL_U64 (uint64_t('T') | (uint64_t('E') << 8) | (uint64_t('S') << 16) | (uint64_t('T') << 24) | (uint64_t('S') << 32)) -#define TESTS_SYMBOL_SER (uint64_t(3) | (TESTS_SYMBOL_U64 << 8)) - -struct asset { - static uint64_t hbd_symbol_ser; - static uint64_t hive_symbol_ser; - share_type amount; - uint64_t symbol; -}; - -}}} // namespace graphene::peerplays_sidechain::hive - -namespace fc { -void to_variant(const graphene::peerplays_sidechain::hive::asset &var, fc::variant &vo, uint32_t max_depth); -void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::asset &vo, uint32_t max_depth); -} // namespace fc - -FC_REFLECT(graphene::peerplays_sidechain::hive::asset, (amount)(symbol)) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/authority.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/authority.hpp deleted file mode 100644 index bd67ae23..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/authority.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include - -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -struct authority { - authority() { - } - - enum classification { - owner = 0, - active = 1, - key = 2, - posting = 3 - }; - - uint32_t weight_threshold = 0; - fc::flat_map account_auths; - fc::flat_map key_auths; -}; - -}}} // namespace graphene::peerplays_sidechain::hive - -FC_REFLECT_ENUM(graphene::peerplays_sidechain::hive::authority::classification, - (owner)(active)(key)(posting)) - -FC_REFLECT(graphene::peerplays_sidechain::hive::authority, - (weight_threshold)(account_auths)(key_auths)) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp deleted file mode 100644 index 1348ce35..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/hive_operations.hpp +++ /dev/null @@ -1,123 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include -#include -#include -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -struct vote_operation {}; -struct comment_operation {}; - -struct transfer_operation { - hive::account_name_type from; - hive::account_name_type to; - hive::asset amount; - std::string memo; -}; - -struct transfer_to_vesting_operation {}; -struct withdraw_vesting_operation {}; -struct limit_order_create_operation {}; -struct limit_order_cancel_operation {}; -struct feed_publish_operation {}; -struct convert_operation {}; -struct account_create_operation {}; - -struct account_update_operation { - hive::account_name_type account; - fc::optional owner; - fc::optional active; - fc::optional posting; - hive::public_key_type memo_key; - std::string json_metadata; -}; - -struct witness_update_operation {}; -struct account_witness_vote_operation {}; -struct account_witness_proxy_operation {}; -struct pow_operation {}; -struct custom_operation {}; -struct report_over_production_operation {}; -struct delete_comment_operation {}; -struct custom_json_operation {}; -struct comment_options_operation {}; -struct set_withdraw_vesting_route_operation {}; -struct limit_order_create2_operation {}; -struct claim_account_operation {}; -struct create_claimed_account_operation {}; -struct request_account_recovery_operation {}; -struct recover_account_operation {}; -struct change_recovery_account_operation {}; -struct escrow_transfer_operation {}; -struct escrow_dispute_operation {}; -struct escrow_release_operation {}; -struct pow2_operation {}; -struct escrow_approve_operation {}; -struct transfer_to_savings_operation {}; -struct transfer_from_savings_operation {}; -struct cancel_transfer_from_savings_operation {}; -struct custom_binary_operation {}; -struct decline_voting_rights_operation {}; -struct reset_account_operation {}; -struct set_reset_account_operation {}; -struct claim_reward_balance_operation {}; - -struct delegate_vesting_shares_operation { - hive::account_name_type delegator; - hive::account_name_type delegatee; - hive::asset vesting_shares; -}; - -}}} // namespace graphene::peerplays_sidechain::hive - -FC_REFLECT(graphene::peerplays_sidechain::hive::vote_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::comment_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_operation, - (from)(to)(amount)(memo)) -FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_to_vesting_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::withdraw_vesting_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::limit_order_create_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::limit_order_cancel_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::feed_publish_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::convert_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::account_create_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::account_update_operation, - (account)(owner)(active)(posting)(memo_key)(json_metadata)) -FC_REFLECT(graphene::peerplays_sidechain::hive::witness_update_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::account_witness_vote_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::account_witness_proxy_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::pow_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::custom_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::report_over_production_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::delete_comment_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::custom_json_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::comment_options_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::set_withdraw_vesting_route_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::limit_order_create2_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::claim_account_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::create_claimed_account_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::request_account_recovery_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::recover_account_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::change_recovery_account_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_transfer_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_dispute_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_release_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::pow2_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_approve_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_to_savings_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_from_savings_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::cancel_transfer_from_savings_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::custom_binary_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::decline_voting_rights_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::reset_account_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::set_reset_account_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::claim_reward_balance_operation, ) -FC_REFLECT(graphene::peerplays_sidechain::hive::delegate_vesting_shares_operation, - (delegator)(delegatee)(vesting_shares)) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/operations.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/operations.hpp deleted file mode 100644 index e64eb1ae..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/operations.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -typedef fc::static_variant< - vote_operation, - comment_operation, - - transfer_operation, - transfer_to_vesting_operation, - withdraw_vesting_operation, - - limit_order_create_operation, - limit_order_cancel_operation, - - feed_publish_operation, - convert_operation, - - account_create_operation, - account_update_operation, - - witness_update_operation, - account_witness_vote_operation, - account_witness_proxy_operation, - - pow_operation, - - custom_operation, - - report_over_production_operation, - - delete_comment_operation, - custom_json_operation, - comment_options_operation, - set_withdraw_vesting_route_operation, - limit_order_create2_operation, - claim_account_operation, - create_claimed_account_operation, - request_account_recovery_operation, - recover_account_operation, - change_recovery_account_operation, - escrow_transfer_operation, - escrow_dispute_operation, - escrow_release_operation, - pow2_operation, - escrow_approve_operation, - transfer_to_savings_operation, - transfer_from_savings_operation, - cancel_transfer_from_savings_operation, - custom_binary_operation, - decline_voting_rights_operation, - reset_account_operation, - set_reset_account_operation, - claim_reward_balance_operation, - delegate_vesting_shares_operation> - hive_operation; - -}}} // namespace graphene::peerplays_sidechain::hive - -namespace fc { - -void to_variant(const graphene::peerplays_sidechain::hive::hive_operation &var, fc::variant &vo, uint32_t max_depth = 5); -void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::hive_operation &vo, uint32_t max_depth = 5); - -} // namespace fc - -FC_REFLECT_TYPENAME(graphene::peerplays_sidechain::hive::hive_operation) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/transaction.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/transaction.hpp deleted file mode 100644 index 8b35b7b3..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/transaction.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include -#include - -#include -#include - -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -struct transaction { - uint16_t ref_block_num = 0; - uint32_t ref_block_prefix = 0; - fc::time_point_sec expiration; - std::vector operations; - extensions_type extensions; - - digest_type digest() const; - transaction_id_type id() const; - digest_type sig_digest(const chain_id_type &chain_id) const; - - void set_expiration(fc::time_point_sec expiration_time); - void set_reference_block(const block_id_type &reference_block); -}; - -struct signed_transaction : public transaction { - - std::vector signatures; - - const signature_type &sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id); - signature_type sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id) const; - void clear(); -}; - -}}} // namespace graphene::peerplays_sidechain::hive - -FC_REFLECT(graphene::peerplays_sidechain::hive::transaction, - (ref_block_num)(ref_block_prefix)(expiration)(operations)(extensions)) - -FC_REFLECT_DERIVED(graphene::peerplays_sidechain::hive::signed_transaction, - (graphene::peerplays_sidechain::hive::transaction), - (signatures)) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp deleted file mode 100644 index f5b986e4..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/hive/types.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include -#include - -namespace graphene { namespace peerplays_sidechain { namespace hive { - -#define KEY_PREFIX_STM "STM" -#define KEY_PREFIX_TST "TST" - -enum network { - mainnet, - testnet -}; - -struct void_t {}; - -typedef fc::static_variant future_extensions; -typedef fc::flat_set extensions_type; - -typedef fc::ecc::private_key private_key_type; -typedef fc::sha256 chain_id_type; -typedef std::string account_name_type; -typedef fc::ripemd160 block_id_type; -//typedef fc::ripemd160 checksum_type; -typedef fc::ripemd160 transaction_id_type; -typedef fc::sha256 digest_type; -typedef fc::ecc::compact_signature signature_type; -typedef fc::safe share_type; -//typedef safe ushare_type; -//typedef uint16_t weight_type; -//typedef uint32_t contribution_id_type; -//typedef fixed_string<32> custom_id_type; - -struct public_key_type { - - static std::string prefix; - - struct binary_key { - binary_key() { - } - uint32_t check = 0; - fc::ecc::public_key_data data; - }; - fc::ecc::public_key_data key_data; - public_key_type(); - public_key_type(const fc::ecc::public_key_data &data); - public_key_type(const fc::ecc::public_key &pubkey); - explicit public_key_type(const std::string &base58str); - operator fc::ecc::public_key_data() const; - operator fc::ecc::public_key() const; - explicit operator std::string() const; - friend bool operator==(const public_key_type &p1, const fc::ecc::public_key &p2); - friend bool operator==(const public_key_type &p1, const public_key_type &p2); - friend bool operator<(const public_key_type &p1, const public_key_type &p2) { - return p1.key_data < p2.key_data; - } - friend bool operator!=(const public_key_type &p1, const public_key_type &p2); -}; - -}}} // namespace graphene::peerplays_sidechain::hive - -namespace fc { -void to_variant(const graphene::peerplays_sidechain::hive::public_key_type &var, fc::variant &vo, uint32_t max_depth = 2); -void from_variant(const fc::variant &var, graphene::peerplays_sidechain::hive::public_key_type &vo, uint32_t max_depth = 2); -} // namespace fc - -FC_REFLECT(graphene::peerplays_sidechain::hive::public_key_type, (key_data)) -FC_REFLECT(graphene::peerplays_sidechain::hive::public_key_type::binary_key, (data)(check)) - -FC_REFLECT(graphene::peerplays_sidechain::hive::void_t, ) -FC_REFLECT_TYPENAME(graphene::peerplays_sidechain::hive::future_extensions) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp index 6adfe944..5b7ea6e9 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp @@ -37,7 +37,6 @@ public: boost::program_options::options_description &cfg) override; virtual void plugin_initialize(const boost::program_options::variables_map &options) override; virtual void plugin_startup() override; - virtual void plugin_shutdown() override; std::unique_ptr my; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp index 21526d05..50dfd505 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp @@ -4,6 +4,7 @@ #include +#include #include #include #include @@ -45,19 +46,15 @@ public: virtual bool process_withdrawal(const son_wallet_withdraw_object &swwo) = 0; virtual std::string process_sidechain_transaction(const sidechain_transaction_object &sto) = 0; virtual std::string send_sidechain_transaction(const sidechain_transaction_object &sto) = 0; - virtual bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) = 0; + virtual int64_t settle_sidechain_transaction(const sidechain_transaction_object &sto) = 0; protected: peerplays_sidechain_plugin &plugin; graphene::chain::database &database; sidechain_type sidechain; - bool debug_rpc_calls; - std::map private_keys; - void on_applied_block(const signed_block &b); - private: }; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp index dd6ebb28..eb218a4c 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp @@ -1,14 +1,13 @@ #pragma once +#include #include #include #include -#include - #include -#include +#include namespace graphene { namespace peerplays_sidechain { @@ -21,7 +20,7 @@ public: class bitcoin_rpc_client { public: - bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password, bool _debug_rpc_calls); + bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password); std::string addmultisigaddress(const uint32_t nrequired, const std::vector public_keys); std::string combinepsbt(const vector &psbts); @@ -51,7 +50,7 @@ public: //bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60); private: - fc::http::reply send_post_request(std::string body, bool show_log); + fc::http::reply send_post_request(std::string body, bool show_log = false); std::string ip; uint32_t rpc_port; @@ -59,7 +58,6 @@ private: std::string password; std::string wallet; std::string wallet_password; - bool debug_rpc_calls; fc::http::header authorization; }; @@ -70,7 +68,7 @@ class zmq_listener { public: zmq_listener(std::string _ip, uint32_t _zmq); - boost::signals2::signal event_received; + fc::signal event_received; private: void handle_zmq(); @@ -97,7 +95,7 @@ public: bool process_withdrawal(const son_wallet_withdraw_object &swwo); std::string process_sidechain_transaction(const sidechain_transaction_object &sto); std::string send_sidechain_transaction(const sidechain_transaction_object &sto); - bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount); + int64_t settle_sidechain_transaction(const sidechain_transaction_object &sto); private: std::string ip; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_hive.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_hive.hpp deleted file mode 100644 index 675c3cdd..00000000 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_hive.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -#include - -#include - -#include - -#include -#include -#include - -namespace graphene { namespace peerplays_sidechain { - -class hive_node_rpc_client : public rpc_client { -public: - hive_node_rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls); - - std::string account_history_api_get_transaction(std::string transaction_id); - std::string block_api_get_block(uint32_t block_number); - std::string condenser_api_get_accounts(std::vector accounts); - std::string condenser_api_get_config(); - std::string database_api_get_dynamic_global_properties(); - std::string database_api_get_version(); - std::string network_broadcast_api_broadcast_transaction(std::string htrx); - - std::string get_account(std::string account); - std::string get_account_memo_key(std::string account); - std::string get_chain_id(); - std::string get_head_block_id(); - std::string get_head_block_time(); - std::string get_is_test_net(); - std::string get_last_irreversible_block_num(); -}; - -class sidechain_net_handler_hive : public sidechain_net_handler { -public: - sidechain_net_handler_hive(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options); - virtual ~sidechain_net_handler_hive(); - - bool process_proposal(const proposal_object &po); - void process_primary_wallet(); - void process_sidechain_addresses(); - bool process_deposit(const son_wallet_deposit_object &swdo); - bool process_withdrawal(const son_wallet_withdraw_object &swwo); - std::string process_sidechain_transaction(const sidechain_transaction_object &sto); - std::string send_sidechain_transaction(const sidechain_transaction_object &sto); - bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount); - -private: - std::string node_ip; - uint32_t node_rpc_port; - std::string node_rpc_user; - std::string node_rpc_password; - hive_node_rpc_client *node_rpc_client; - - hive::chain_id_type chain_id; - hive::network network_type; - - uint64_t last_block_received; - fc::future _listener_task; - boost::signals2::signal event_received; - void schedule_hive_listener(); - void hive_listener_loop(); - void handle_event(const std::string &event_data); -}; - -}} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp index 69eea1a9..aa094d95 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp @@ -4,6 +4,8 @@ #include +#include + namespace graphene { namespace peerplays_sidechain { class sidechain_net_handler_peerplays : public sidechain_net_handler { @@ -18,9 +20,10 @@ public: bool process_withdrawal(const son_wallet_withdraw_object &swwo); std::string process_sidechain_transaction(const sidechain_transaction_object &sto); std::string send_sidechain_transaction(const sidechain_transaction_object &sto); - bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount); + int64_t settle_sidechain_transaction(const sidechain_transaction_object &sto); private: + void on_applied_block(const signed_block &b); }; }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp index a35c1933..c2d40e14 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp @@ -29,8 +29,6 @@ private: peerplays_sidechain_plugin &plugin; graphene::chain::database &database; std::vector> net_handlers; - - void on_applied_block(const signed_block &b); }; }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index 02a046fc..7a57effb 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -29,7 +29,6 @@ public: boost::program_options::options_description &cfg); void plugin_initialize(const boost::program_options::variables_map &opt); void plugin_startup(); - void plugin_shutdown(); std::set &get_sons(); const son_id_type get_current_son_id(); @@ -69,15 +68,8 @@ private: bool config_ready_son; bool config_ready_bitcoin; - bool config_ready_ethereum; - bool config_ready_hive; bool config_ready_peerplays; - bool sidechain_enabled_bitcoin; - bool sidechain_enabled_ethereum; - bool sidechain_enabled_hive; - bool sidechain_enabled_peerplays; - son_id_type current_son_id; std::unique_ptr net_manager; @@ -96,13 +88,7 @@ peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidec plugin(_plugin), config_ready_son(false), config_ready_bitcoin(false), - config_ready_ethereum(false), - config_ready_hive(false), config_ready_peerplays(false), - sidechain_enabled_bitcoin(false), - sidechain_enabled_ethereum(false), - sidechain_enabled_hive(false), - sidechain_enabled_peerplays(false), current_son_id(son_id_type(std::numeric_limits().max())), net_manager(nullptr), first_block_skipped(false) { @@ -139,12 +125,6 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options( cli.add_options()("son-ids", bpo::value(), ("IDs of multiple SONs controlled by this node (e.g. [" + son_id_example + ", " + son_id_example2 + "], quotes are required)").c_str()); cli.add_options()("peerplays-private-key", bpo::value>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR(std::make_pair(chain::public_key_type(default_priv_key.get_public_key()), graphene::utilities::key_to_wif(default_priv_key))), "Tuple of [PublicKey, WIF private key] (may specify multiple times)"); - - cli.add_options()("sidechain-retry-threshold", bpo::value()->default_value(150), "Sidechain retry throttling threshold"); - - cli.add_options()("debug-rpc-calls", bpo::value()->default_value(false), "Outputs RPC calls to console"); - - cli.add_options()("bitcoin-sidechain-enabled", bpo::value()->default_value(false), "Bitcoin sidechain handler enabled"); cli.add_options()("bitcoin-node-ip", bpo::value()->default_value("127.0.0.1"), "IP address of Bitcoin node"); cli.add_options()("bitcoin-node-zmq-port", bpo::value()->default_value(11111), "ZMQ port of Bitcoin node"); cli.add_options()("bitcoin-node-rpc-port", bpo::value()->default_value(8332), "RPC port of Bitcoin node"); @@ -154,15 +134,7 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options( cli.add_options()("bitcoin-wallet-password", bpo::value(), "Bitcoin wallet password"); cli.add_options()("bitcoin-private-key", bpo::value>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR(std::make_pair("02d0f137e717fb3aab7aff99904001d49a0a636c5e1342f8927a4ba2eaee8e9772", "cVN31uC9sTEr392DLVUEjrtMgLA8Yb3fpYmTRj7bomTm6nn2ANPr")), "Tuple of [Bitcoin public key, Bitcoin private key] (may specify multiple times)"); - - cli.add_options()("hive-sidechain-enabled", bpo::value()->default_value(false), "Hive sidechain handler enabled"); - cli.add_options()("hive-node-ip", bpo::value()->default_value("127.0.0.1"), "Hive node IP address"); - cli.add_options()("hive-node-rpc-port", bpo::value()->default_value(28090), "Hive node RPC port"); - cli.add_options()("hive-node-rpc-user", bpo::value(), "Hive node RPC user"); - cli.add_options()("hive-node-rpc-password", bpo::value(), "Hive node RPC password"); - cli.add_options()("hive-private-key", bpo::value>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR(std::make_pair("TST6LLegbAgLAy28EHrffBVuANFWcFgmqRMW13wBmTExqFE9SCkg4", "5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n")), - "Tuple of [Hive public key, Hive private key] (may specify multiple times)"); - + cli.add_options()("sidechain-retry-threshold", bpo::value()->default_value(150), "Sidechain retry throttling threshold"); cfg.add(cli); } @@ -171,10 +143,8 @@ 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")) { - vector v = fc::json::from_string(options.at("son-ids").as()).as>(5); - sons.insert(v.begin(), v.end()); - } + if (options.count("son-ids")) + boost::insert(sons, fc::json::from_string(options.at("son-ids").as()).as>(5)); config_ready_son = config_ready_son && !sons.empty(); #ifndef ENABLE_MULTIPLE_SONS @@ -202,9 +172,7 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt } config_ready_son = config_ready_son && !private_keys.empty(); } - if (options.count("sidechain-retry-threshold")) { - retries_threshold = options.at("sidechain-retry-threshold").as(); - } + retries_threshold = options.at("sidechain-retry-threshold").as(); ilog("sidechain-retry-threshold: ${sidechain-retry-threshold}", ("sidechain-retry-threshold", retries_threshold)); } if (!config_ready_son) { @@ -212,47 +180,27 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt throw; } - sidechain_enabled_bitcoin = options.at("bitcoin-sidechain-enabled").as(); config_ready_bitcoin = options.count("bitcoin-node-ip") && options.count("bitcoin-node-zmq-port") && options.count("bitcoin-node-rpc-port") && options.count("bitcoin-node-rpc-user") && options.count("bitcoin-node-rpc-password") && - /*options.count("bitcoin-wallet") && options.count("bitcoin-wallet-password") &&*/ + /*options.count( "bitcoin-wallet" ) && options.count( "bitcoin-wallet-password" ) &&*/ options.count("bitcoin-private-key"); if (!config_ready_bitcoin) { wlog("Haven't set up Bitcoin sidechain parameters"); } - //sidechain_enabled_ethereum = options.at("ethereum-sidechain-enabled").as(); - //config_ready_ethereum = options.count("ethereum-node-ip") && - // options.count("ethereum-address") && - // options.count("ethereum-public-key") && options.count("ethereum-private-key"); + //config_ready_ethereum = options.count( "ethereum-node-ip" ) && + // options.count( "ethereum-address" ) && options.count( "ethereum-public-key" ) && options.count( "ethereum-private-key" ); //if (!config_ready_ethereum) { // wlog("Haven't set up Ethereum sidechain parameters"); //} - sidechain_enabled_hive = options.at("hive-sidechain-enabled").as(); - config_ready_hive = options.count("hive-node-ip") && - options.count("hive-node-rpc-port") && - /*options.count("hive-node-rpc-user") && options.count("hive-node-rpc-password") &&*/ - options.count("hive-private-key"); - if (!config_ready_hive) { - wlog("Haven't set up Hive sidechain parameters"); - } - -#ifdef ENABLE_PEERPLAYS_ASSET_DEPOSITS - sidechain_enabled_peerplays = true; //options.at("peerplays-sidechain-enabled").as(); -#else - sidechain_enabled_peerplays = false; -#endif config_ready_peerplays = true; if (!config_ready_peerplays) { wlog("Haven't set up Peerplays sidechain parameters"); } - if (!(config_ready_bitcoin && - /*config_ready_ethereum &&*/ - config_ready_hive && - config_ready_peerplays)) { + if (!(config_ready_bitcoin /*&& config_ready_ethereum*/ && config_ready_peerplays)) { wlog("Haven't set up any sidechain parameters"); throw; } @@ -270,22 +218,17 @@ void peerplays_sidechain_plugin_impl::plugin_startup() { net_manager = std::unique_ptr(new sidechain_net_manager(plugin)); - if (sidechain_enabled_bitcoin && config_ready_bitcoin) { + if (config_ready_bitcoin) { net_manager->create_handler(sidechain_type::bitcoin, options); ilog("Bitcoin sidechain handler running"); } - //if (sidechain_enabled_ethereum && config_ready_ethereum) { + //if (config_ready_ethereum) { // net_manager->create_handler(sidechain_type::ethereum, options); // ilog("Ethereum sidechain handler running"); //} - if (sidechain_enabled_hive && config_ready_hive) { - net_manager->create_handler(sidechain_type::hive, options); - ilog("Hive sidechain handler running"); - } - - if (sidechain_enabled_peerplays && config_ready_peerplays) { + if (config_ready_peerplays) { net_manager->create_handler(sidechain_type::peerplays, options); ilog("Peerplays sidechain handler running"); } @@ -295,9 +238,6 @@ void peerplays_sidechain_plugin_impl::plugin_startup() { }); } -void peerplays_sidechain_plugin_impl::plugin_shutdown() { -} - std::set &peerplays_sidechain_plugin_impl::get_sons() { return sons; } @@ -448,15 +388,9 @@ void peerplays_sidechain_plugin_impl::son_processing() { return; } - //fc::time_point now_fine = fc::time_point::now(); - //fc::time_point_sec now = now_fine + fc::microseconds(500000); - //if (plugin.database().get_slot_time(1) < now) { - // return; // Not synced - //} - fc::time_point now_fine = fc::time_point::now(); - fc::time_point_sec now = now_fine - fc::milliseconds(3000); - if (plugin.database().head_block_time() < now) { + fc::time_point_sec now = now_fine + fc::microseconds(500000); + if (plugin.database().get_slot_time(1) < now) { return; // Not synced } @@ -750,12 +684,6 @@ void peerplays_sidechain_plugin::plugin_startup() { ilog("peerplays sidechain plugin: plugin_startup() end"); } -void peerplays_sidechain_plugin::plugin_shutdown() { - ilog("peerplays sidechain plugin: plugin_shutdown() begin"); - my->plugin_shutdown(); - ilog("peerplays sidechain plugin: plugin_shutdown() end"); -} - std::set &peerplays_sidechain_plugin::get_sons() { return my->get_sons(); } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp index 06a76502..d025c178 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -1,21 +1,14 @@ #include -#include - #include #include #include -#include namespace graphene { namespace peerplays_sidechain { sidechain_net_handler::sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) : plugin(_plugin), database(_plugin.database()) { - - database.applied_block.connect([&](const signed_block &b) { - on_applied_block(b); - }); } sidechain_net_handler::~sidechain_net_handler() { @@ -168,25 +161,21 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ const chain::global_property_object &gpo = database.get_global_properties(); - bool enable_peerplays_asset_deposits = false; + asset_id_type btc_asset_id = database.get_global_properties().parameters.btc_asset(); + std::string btc_asset_id_str = fc::to_string(btc_asset_id.space_id) + "." + + fc::to_string(btc_asset_id.type_id) + "." + + fc::to_string((uint64_t)btc_asset_id.instance); + #ifdef ENABLE_PEERPLAYS_ASSET_DEPOSITS - //enable_peerplays_asset_deposits = (sed.sidechain == sidechain_type::peerplays) && - // (sed.sidechain_currency.compare("BTC") != 0) && - // (sed.sidechain_currency.compare("HBD") != 0) && - // (sed.sidechain_currency.compare("HIVE") != 0); + // Accepts BTC and peerplays asset deposits + bool deposit_condition = ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare(btc_asset_id_str) != 0)); + bool withdraw_condition = ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare(btc_asset_id_str) == 0)); +#else + // Accepts BTC deposits only + bool deposit_condition = ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare("BTC") == 0)); + bool withdraw_condition = ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare(btc_asset_id_str) == 0)); #endif - bool deposit_condition = (sed.peerplays_to == gpo.parameters.son_account()) && - (((sed.sidechain == sidechain_type::bitcoin) && (sed.sidechain_currency.compare("BTC") == 0)) || - ((sed.sidechain == sidechain_type::hive) && (sed.sidechain_currency.compare("HBD") == 0)) || - ((sed.sidechain == sidechain_type::hive) && (sed.sidechain_currency.compare("HIVE") == 0)) || - enable_peerplays_asset_deposits); - - bool withdraw_condition = (sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain == sidechain_type::peerplays) && - ((sed.sidechain_currency == object_id_to_string(gpo.parameters.btc_asset())) || - (sed.sidechain_currency == object_id_to_string(gpo.parameters.hbd_asset())) || - (sed.sidechain_currency == object_id_to_string(gpo.parameters.hive_asset()))); - // Deposit request if (deposit_condition) { @@ -225,32 +214,11 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ // Withdrawal request if (withdraw_condition) { - std::string withdraw_address = ""; + // BTC Payout only (for now) const auto &sidechain_addresses_idx = database.get_index_type().indices().get(); - const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain, time_point_sec::maximum())); - if (addr_itr != sidechain_addresses_idx.end()) { - withdraw_address = addr_itr->withdraw_address; - } else { - withdraw_address = sed.sidechain_from; - } - - std::string withdraw_currency = ""; - price withdraw_currency_price = {}; - if (sed.sidechain_currency == object_id_to_string(gpo.parameters.btc_asset())) { - withdraw_currency = "BTC"; - withdraw_currency_price = database.get(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate; - } - if (sed.sidechain_currency == object_id_to_string(gpo.parameters.hbd_asset())) { - withdraw_currency = "HBD"; - withdraw_currency_price = database.get(database.get_global_properties().parameters.hbd_asset()).options.core_exchange_rate; - } - if (sed.sidechain_currency == object_id_to_string(gpo.parameters.hive_asset())) { - withdraw_currency = "HIVE"; - withdraw_currency_price = database.get(database.get_global_properties().parameters.hive_asset()).options.core_exchange_rate; - } - if (withdraw_currency.empty()) { + const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain_type::bitcoin, time_point_sec::maximum())); + if (addr_itr == sidechain_addresses_idx.end()) return; - } for (son_id_type son_id : plugin.get_sons()) { if (plugin.is_active_son(son_id)) { @@ -265,10 +233,12 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ op.peerplays_transaction_id = sed.sidechain_transaction_id; op.peerplays_from = sed.peerplays_from; op.peerplays_asset = sed.peerplays_asset; - op.withdraw_sidechain = sidechain; - op.withdraw_address = withdraw_address; - op.withdraw_currency = withdraw_currency; - op.withdraw_amount = sed.peerplays_asset.amount * withdraw_currency_price.quote.amount / withdraw_currency_price.base.amount; + // BTC payout only (for now) + op.withdraw_sidechain = sidechain_type::bitcoin; + op.withdraw_address = addr_itr->withdraw_address; + op.withdraw_currency = "BTC"; + price btc_price = database.get(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate; + op.withdraw_amount = sed.peerplays_asset.amount * btc_price.quote.amount / btc_price.base.amount; signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), op); try { @@ -419,13 +389,9 @@ void sidechain_net_handler::process_deposits() { } //Ignore the deposits which are not valid anymore, considered refunds. const auto &sidechain_addresses_idx = database.get_index_type().indices().get(); - const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, swdo.sidechain_from, time_point_sec::maximum())); + const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, swdo.sidechain_to, time_point_sec::maximum())); if (addr_itr == sidechain_addresses_idx.end()) { - const auto &account_idx = database.get_index_type().indices().get(); - const auto &account_itr = account_idx.find(swdo.sidechain_from); - if (account_itr == account_idx.end()) { - return; - } + return; } ilog("Deposit to process: ${swdo}", ("swdo", swdo)); @@ -566,10 +532,9 @@ void sidechain_net_handler::settle_sidechain_transactions() { ilog("Sidechain transaction to settle: ${sto}", ("sto", sto.id)); - asset settle_amount; - bool settle_sidechain_result = settle_sidechain_transaction(sto, settle_amount); + int64_t settle_amount = settle_sidechain_transaction(sto); - if (settle_sidechain_result == false) { + if (settle_amount < 0) { wlog("Sidechain transaction not settled: ${sto}", ("sto", sto.id)); return; } @@ -586,12 +551,12 @@ void sidechain_net_handler::settle_sidechain_transactions() { sts_op.sidechain_transaction_id = sto.id; proposal_op.proposed_ops.emplace_back(sts_op); - if (settle_amount.amount != 0) { + if (settle_amount != 0) { if (sto.object_id.is()) { asset_issue_operation ai_op; ai_op.fee = asset(2001000); ai_op.issuer = gpo.parameters.son_account(); - ai_op.asset_to_issue = settle_amount; + ai_op.asset_to_issue = asset(settle_amount, database.get_global_properties().parameters.btc_asset()); ai_op.issue_to_account = database.get(sto.object_id).peerplays_from; proposal_op.proposed_ops.emplace_back(ai_op); } @@ -600,7 +565,7 @@ void sidechain_net_handler::settle_sidechain_transactions() { asset_reserve_operation ar_op; ar_op.fee = asset(2001000); ar_op.payer = gpo.parameters.son_account(); - ar_op.amount_to_reserve = settle_amount; + ar_op.amount_to_reserve = asset(settle_amount, database.get_global_properties().parameters.btc_asset()); proposal_op.proposed_ops.emplace_back(ar_op); } } @@ -618,63 +583,4 @@ void sidechain_net_handler::settle_sidechain_transactions() { }); } -void sidechain_net_handler::on_applied_block(const signed_block &b) { - - const chain::global_property_object &gpo = plugin.database().get_global_properties(); - - for (const auto &trx : b.transactions) { - size_t operation_index = -1; - for (auto op : trx.operations) { - operation_index = operation_index + 1; - if (op.which() == operation::tag::value) { - transfer_operation transfer_op = op.get(); - - if (transfer_op.to != gpo.parameters.son_account()) { - continue; - } - - bool is_tracked_asset = - ((sidechain == sidechain_type::bitcoin) && (transfer_op.amount.asset_id == gpo.parameters.btc_asset())) || - ((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hbd_asset())) || - ((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hive_asset())); - - if (!is_tracked_asset) { - continue; - } - - std::string sidechain_from = object_id_to_string(transfer_op.from); - std::string memo = ""; - if (transfer_op.memo) { - memo = transfer_op.memo->get_message(fc::ecc::private_key(), public_key_type()); - boost::trim(memo); - if (!memo.empty()) { - sidechain_from = memo; - } - } - - std::stringstream ss; - ss << "peerplays" - << "-" << trx.id().str() << "-" << operation_index; - std::string sidechain_uid = ss.str(); - - sidechain_event_data sed; - sed.timestamp = database.head_block_time(); - sed.block_num = database.head_block_num(); - sed.sidechain = sidechain_type::peerplays; - sed.sidechain_uid = sidechain_uid; - sed.sidechain_transaction_id = trx.id().str(); - sed.sidechain_from = sidechain_from; - sed.sidechain_to = object_id_to_string(transfer_op.to); - sed.sidechain_currency = object_id_to_string(transfer_op.amount.asset_id); - sed.sidechain_amount = transfer_op.amount.amount; - sed.peerplays_from = transfer_op.from; - sed.peerplays_to = transfer_op.to; - price asset_price = database.get(transfer_op.amount.asset_id).options.core_exchange_rate; - sed.peerplays_asset = asset(transfer_op.amount.amount * asset_price.base.amount / asset_price.quote.amount); - sidechain_event_data_received(sed); - } - } - } -} - }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index ca4e9149..7c0b0074 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -26,14 +26,13 @@ namespace graphene { namespace peerplays_sidechain { // ============================================================================= -bitcoin_rpc_client::bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password, bool _debug_rpc_calls) : +bitcoin_rpc_client::bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password) : ip(_ip), rpc_port(_rpc), user(_user), password(_password), wallet(_wallet), - wallet_password(_wallet_password), - debug_rpc_calls(_debug_rpc_calls) { + wallet_password(_wallet_password) { authorization.key = "Authorization"; authorization.val = "Basic " + fc::base64_encode(user + ":" + password); } @@ -52,7 +51,7 @@ std::string bitcoin_rpc_client::addmultisigaddress(const uint32_t nrequired, con params = params + pubkeys + std::string("]"); body = body + params + std::string(", null, \"bech32\"] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -84,7 +83,7 @@ std::string bitcoin_rpc_client::combinepsbt(const vector &psbts) { params = params + std::string("\"") + psbt + std::string("\""); } body = body + params + std::string("]] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -121,7 +120,7 @@ std::string bitcoin_rpc_client::createmultisig(const uint32_t nrequired, const s params = params + pubkeys + std::string("]"); body = body + params + std::string(", \"p2sh-segwit\" ] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -163,7 +162,7 @@ std::string bitcoin_rpc_client::createpsbt(const std::vector &ins, co } body += std::string("]] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -207,7 +206,7 @@ std::string bitcoin_rpc_client::createrawtransaction(const std::vector bitcoin_rpc_client::listunspent(const uint32_t minconf, c "\"listunspent\", \"params\": [" + std::to_string(minconf) + "," + std::to_string(maxconf) + "] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); std::vector result; @@ -618,7 +617,7 @@ std::vector bitcoin_rpc_client::listunspent_by_address_and_amount(con body += std::to_string(minimum_amount); body += std::string("} ] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); std::vector result; if (reply.body.empty()) { @@ -653,7 +652,7 @@ std::string bitcoin_rpc_client::loadwallet(const std::string &filename) { "\"loadwallet\", \"params\": [\"" + filename + "\"] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -681,7 +680,7 @@ std::string bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) { "\"method\": \"sendrawtransaction\", \"params\": [") + std::string("\"") + tx_hex + std::string("\"") + std::string("] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -708,7 +707,7 @@ std::string bitcoin_rpc_client::signrawtransactionwithwallet(const std::string & std::string params = "\"" + tx_hash + "\""; body = body + params + std::string("]}"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -734,7 +733,7 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) { "\"unloadwallet\", \"params\": [\"" + filename + "\"] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -761,7 +760,7 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) { // std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletlock\", \"method\": " // "\"walletlock\", \"params\": [] }"); // -// const auto reply = send_post_request(body, debug_rpc_calls); +// const auto reply = send_post_request(body); // // if (reply.body.empty()) { // wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -789,7 +788,7 @@ std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) { "\"walletprocesspsbt\", \"params\": [\"" + tx_psbt + "\"] }"); - const auto reply = send_post_request(body, debug_rpc_calls); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -815,7 +814,7 @@ std::string bitcoin_rpc_client::walletprocesspsbt(std::string const &tx_psbt) { // "\"walletpassphrase\", \"params\": [\"" + // passphrase + "\", " + std::to_string(timeout) + "] }"); // -// const auto reply = send_post_request(body, debug_rpc_calls); +// const auto reply = send_post_request(body); // // if (reply.body.empty()) { // wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -912,10 +911,6 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain sidechain_net_handler(_plugin, options) { sidechain = sidechain_type::bitcoin; - if (options.count("debug-rpc-calls")) { - debug_rpc_calls = options.at("debug-rpc-calls").as(); - } - ip = options.at("bitcoin-node-ip").as(); zmq_port = options.at("bitcoin-node-zmq-port").as(); rpc_port = options.at("bitcoin-node-rpc-port").as(); @@ -950,7 +945,7 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain FC_ASSERT(false); } - bitcoin_client = std::unique_ptr(new bitcoin_rpc_client(ip, rpc_port, rpc_user, rpc_password, wallet, wallet_password, debug_rpc_calls)); + bitcoin_client = std::unique_ptr(new bitcoin_rpc_client(ip, rpc_port, rpc_user, rpc_password, wallet, wallet_password)); if (!wallet.empty()) { bitcoin_client->loadwallet(wallet); } @@ -994,7 +989,7 @@ sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() { bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) { - //ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id())); + ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id())); bool should_approve = false; @@ -1099,7 +1094,7 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) if (swdo != idx.end()) { std::string swdo_txid = swdo->sidechain_transaction_id; - std::string swdo_address = swdo->sidechain_from; + std::string swdo_address = swdo->sidechain_to; uint64_t swdo_amount = swdo->sidechain_amount.value; uint64_t swdo_vout = std::stoll(swdo->sidechain_uid.substr(swdo->sidechain_uid.find_last_of("-") + 1)); @@ -1113,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 = ""; - uint64_t tx_amount = -1; - uint64_t tx_vout = -1; + int64_t tx_amount = -1; + int64_t tx_vout = -1; for (auto &input : tx_json.get_child("result.vout")) { std::string tx_vout_s = input.second.get("n"); @@ -1359,7 +1354,6 @@ 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))); @@ -1385,14 +1379,13 @@ 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)); - retval = true; + return true; } catch (fc::exception &e) { - elog("Sending transaction for sidechain address update operation failed with exception ${e}", ("e", e.what())); - retval = false; + elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what())); + return false; } } } - return retval; }); } @@ -1492,15 +1485,16 @@ std::string sidechain_net_handler_bitcoin::send_sidechain_transaction(const side return send_transaction(sto); } -bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) { +int64_t sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain_transaction_object &sto) { if (sto.object_id.is()) { - settle_amount = asset(0, database.get_global_properties().parameters.btc_asset()); - return true; + return 0; } + int64_t settle_amount = -1; + if (sto.sidechain_transaction.empty()) { - return false; + return settle_amount; } std::string tx_str = bitcoin_client->getrawtransaction(sto.sidechain_transaction, true); @@ -1509,7 +1503,7 @@ bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain boost::property_tree::read_json(tx_ss, tx_json); if ((tx_json.count("error")) && (!tx_json.get_child("error").empty())) { - return false; + return settle_amount; } const chain::global_property_object &gpo = database.get_global_properties(); @@ -1540,17 +1534,15 @@ bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain } } } - settle_amount = asset(tx_amount, database.get_global_properties().parameters.btc_asset()); - return true; + settle_amount = tx_amount; } if (sto.object_id.is()) { auto swwo = database.get(sto.object_id); - settle_amount = asset(swwo.withdraw_amount, database.get_global_properties().parameters.btc_asset()); - return true; + settle_amount = swwo.withdraw_amount.value; } } - return false; + return settle_amount; } std::string sidechain_net_handler_bitcoin::create_primary_wallet_address(const std::vector &son_pubkeys) { @@ -1576,17 +1568,7 @@ std::string sidechain_net_handler_bitcoin::create_primary_wallet_address(const s std::string sidechain_net_handler_bitcoin::create_primary_wallet_transaction(const son_wallet_object &prev_swo, std::string new_sw_address) { - const auto &address_data = prev_swo.addresses.find(sidechain_type::bitcoin); - if (address_data == prev_swo.addresses.end()) { - return ""; - } - - std::string s = address_data->second; - if (s.empty()) { - return ""; - } - - std::stringstream prev_sw_ss(s); + std::stringstream prev_sw_ss(prev_swo.addresses.find(sidechain_type::bitcoin)->second); boost::property_tree::ptree prev_sw_pt; boost::property_tree::read_json(prev_sw_ss, prev_sw_pt); std::string prev_pw_address = prev_sw_pt.get("address"); @@ -1631,7 +1613,7 @@ std::string sidechain_net_handler_bitcoin::create_deposit_transaction(const son_ return ""; } //Get redeem script for deposit address - std::string redeem_script = get_redeemscript_for_userdeposit(swdo.sidechain_from); + std::string redeem_script = get_redeemscript_for_userdeposit(swdo.sidechain_to); std::string pw_address_json = obj->addresses.find(sidechain_type::bitcoin)->second; std::stringstream ss(pw_address_json); @@ -1681,11 +1663,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"); - int64_t fee_rate = bitcoin_client->estimatesmartfee(); - int64_t min_fee_rate = 1000; + uint64_t fee_rate = bitcoin_client->estimatesmartfee(); + uint64_t min_fee_rate = 1000; fee_rate = std::max(fee_rate, min_fee_rate); - int64_t total_amount = 0; + uint64_t total_amount = 0; std::vector inputs = bitcoin_client->listunspent_by_address_and_amount(pw_address, 0); if (inputs.size() == 0) { @@ -1823,8 +1805,8 @@ void sidechain_net_handler_bitcoin::handle_event(const std::string &event_data) sed.sidechain = addr_itr->sidechain; sed.sidechain_uid = sidechain_uid; sed.sidechain_transaction_id = v.out.hash_tx; - sed.sidechain_from = v.address; - sed.sidechain_to = ""; + sed.sidechain_from = ""; + sed.sidechain_to = v.address; sed.sidechain_currency = "BTC"; sed.sidechain_amount = v.out.amount; sed.peerplays_from = addr_itr->sidechain_address_account; diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp deleted file mode 100644 index 3b3701dd..00000000 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp +++ /dev/null @@ -1,971 +0,0 @@ -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace graphene { namespace peerplays_sidechain { - -std::string resolve_host_addr(const std::string &host_name) { - using namespace boost::asio; - io_service service; - ip::tcp::resolver resolver(service); - auto query = ip::tcp::resolver::query(host_name, std::string()); - auto iter = resolver.resolve(query); - auto endpoint = *iter; - auto addr = ((ip::tcp::endpoint)endpoint).address(); - return addr.to_string(); -} - -std::string strip_proto_name(const std::string &url, std::string *schema) { - auto index = url.find("://"); - if (index == std::string::npos) { - if (schema) - schema->clear(); - return url; - } - if (schema) - schema->assign(&url[0], &url[index + 3]); - return url.substr(index + 3); -} - -}} // namespace graphene::peerplays_sidechain - -namespace graphene { namespace peerplays_sidechain { - -hive_node_rpc_client::hive_node_rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls) : - rpc_client(_ip, _port, _user, _password, _debug_rpc_calls) { -} - -std::string hive_node_rpc_client::account_history_api_get_transaction(std::string transaction_id) { - std::string params = "{ \"id\": \"" + transaction_id + "\" }"; - return send_post_request("account_history_api.get_transaction", params, debug_rpc_calls); -} - -std::string hive_node_rpc_client::block_api_get_block(uint32_t block_number) { - std::string params = "{ \"block_num\": " + std::to_string(block_number) + " }"; - return send_post_request("block_api.get_block", params, debug_rpc_calls); -} - -std::string hive_node_rpc_client::condenser_api_get_accounts(std::vector accounts) { - std::string params = ""; - for (auto account : accounts) { - if (!params.empty()) { - params = params + ","; - } - params = "\"" + account + "\""; - } - params = "[[" + params + "]]"; - return send_post_request("condenser_api.get_accounts", params, debug_rpc_calls); -} - -std::string hive_node_rpc_client::condenser_api_get_config() { - std::string params = "[]"; - return send_post_request("condenser_api.get_config", params, debug_rpc_calls); -} - -std::string hive_node_rpc_client::database_api_get_dynamic_global_properties() { - return send_post_request("database_api.get_dynamic_global_properties", "", debug_rpc_calls); -} - -std::string hive_node_rpc_client::database_api_get_version() { - return send_post_request("database_api.get_version", "", debug_rpc_calls); -} - -std::string hive_node_rpc_client::network_broadcast_api_broadcast_transaction(std::string htrx) { - std::string params = "{ \"trx\": " + htrx + ", \"max_block_age\": -1 }"; - return send_post_request("network_broadcast_api.broadcast_transaction", params, debug_rpc_calls); -} - -std::string hive_node_rpc_client::get_account(std::string account) { - std::vector accounts; - accounts.push_back(account); - std::string reply_str = condenser_api_get_accounts(accounts); - return retrieve_array_value_from_reply(reply_str, "", 0); -} - -std::string hive_node_rpc_client::get_account_memo_key(std::string account) { - std::string reply_str = get_account(account); - reply_str = "{\"result\":" + reply_str + "}"; - return retrieve_value_from_reply(reply_str, "memo_key"); -} - -std::string hive_node_rpc_client::get_chain_id() { - std::string reply_str = database_api_get_version(); - return retrieve_value_from_reply(reply_str, "chain_id"); -} - -std::string hive_node_rpc_client::get_head_block_id() { - std::string reply_str = database_api_get_dynamic_global_properties(); - return retrieve_value_from_reply(reply_str, "head_block_id"); -} - -std::string hive_node_rpc_client::get_head_block_time() { - std::string reply_str = database_api_get_dynamic_global_properties(); - return retrieve_value_from_reply(reply_str, "time"); -} - -std::string hive_node_rpc_client::get_is_test_net() { - std::string reply_str = condenser_api_get_config(); - return retrieve_value_from_reply(reply_str, "IS_TEST_NET"); -} - -std::string hive_node_rpc_client::get_last_irreversible_block_num() { - std::string reply_str = database_api_get_dynamic_global_properties(); - return retrieve_value_from_reply(reply_str, "last_irreversible_block_num"); -} - -sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) : - sidechain_net_handler(_plugin, options) { - sidechain = sidechain_type::hive; - - if (options.count("debug-rpc-calls")) { - debug_rpc_calls = options.at("debug-rpc-calls").as(); - } - - node_ip = options.at("hive-node-ip").as(); - node_rpc_port = options.at("hive-node-rpc-port").as(); - if (options.count("hive-node-rpc-user")) { - node_rpc_user = options.at("hive-node-rpc-user").as(); - } else { - node_rpc_user = ""; - } - if (options.count("hive-node-rpc-password")) { - node_rpc_password = options.at("hive-node-rpc-password").as(); - } else { - node_rpc_password = ""; - } - - if (options.count("hive-private-key")) { - const std::vector pub_priv_keys = options["hive-private-key"].as>(); - for (const std::string &itr_key_pair : pub_priv_keys) { - auto key_pair = graphene::app::dejsonify>(itr_key_pair, 5); - ilog("Hive Public Key: ${public}", ("public", key_pair.first)); - if (!key_pair.first.length() || !key_pair.second.length()) { - FC_THROW("Invalid public private key pair."); - } - private_keys[key_pair.first] = key_pair.second; - } - } - - node_rpc_client = new hive_node_rpc_client(node_ip, node_rpc_port, node_rpc_user, node_rpc_password, debug_rpc_calls); - - std::string chain_id_str = node_rpc_client->get_chain_id(); - if (chain_id_str.empty()) { - elog("No Hive node running at ${ip} or wrong rpc port: ${port}", ("ip", node_ip)("port", node_rpc_port)); - FC_ASSERT(false); - } - chain_id = chain_id_type(chain_id_str); - - std::string is_test_net = node_rpc_client->get_is_test_net(); - network_type = is_test_net.compare("true") == 0 ? hive::network::testnet : hive::network::mainnet; - if (network_type == hive::network::mainnet) { - ilog("Running on Hive mainnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str)); - hive::asset::hbd_symbol_ser = HBD_SYMBOL_SER; - hive::asset::hive_symbol_ser = HIVE_SYMBOL_SER; - hive::public_key_type::prefix = KEY_PREFIX_STM; - } else { - ilog("Running on Hive testnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str)); - hive::asset::hbd_symbol_ser = TBD_SYMBOL_SER; - hive::asset::hive_symbol_ser = TESTS_SYMBOL_SER; - hive::public_key_type::prefix = KEY_PREFIX_TST; - } - - last_block_received = 0; - schedule_hive_listener(); - event_received.connect([this](const std::string &event_data) { - std::thread(&sidechain_net_handler_hive::handle_event, this, event_data).detach(); - }); -} - -sidechain_net_handler_hive::~sidechain_net_handler_hive() { -} - -bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) { - //ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id())); - - bool should_approve = false; - - const chain::global_property_object &gpo = database.get_global_properties(); - - int32_t op_idx_0 = -1; - chain::operation op_obj_idx_0; - - if (po.proposed_transaction.operations.size() >= 1) { - op_idx_0 = po.proposed_transaction.operations[0].which(); - op_obj_idx_0 = po.proposed_transaction.operations[0]; - } - - 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(); - op_obj_idx_1 = po.proposed_transaction.operations[1]; - } - - switch (op_idx_0) { - - case chain::operation::tag::value: { - bool address_ok = false; - bool transaction_ok = false; - son_wallet_id_type swo_id = op_obj_idx_0.get().son_wallet_id; - const auto &idx = database.get_index_type().indices().get(); - const auto swo = idx.find(swo_id); - if (swo != idx.end()) { - - auto active_sons = gpo.active_sons; - vector wallet_sons = swo->sons; - - bool son_sets_equal = (active_sons.size() == wallet_sons.size()); - - if (son_sets_equal) { - for (size_t i = 0; i < active_sons.size(); i++) { - son_sets_equal = son_sets_equal && active_sons.at(i) == wallet_sons.at(i); - } - } - - if (son_sets_equal) { - address_ok = (op_obj_idx_0.get().address == "son-account"); - } - - if (po.proposed_transaction.operations.size() >= 2) { - object_id_type object_id = op_obj_idx_1.get().object_id; - std::string op_tx_str = op_obj_idx_1.get().transaction; - - const auto &st_idx = database.get_index_type().indices().get(); - const auto st = st_idx.find(object_id); - if (st == st_idx.end()) { - - std::string tx_str = ""; - - if (object_id.is()) { - const auto &idx = database.get_index_type().indices().get(); - const auto swo = idx.find(object_id); - if (swo != idx.end()) { - - std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str)); - hive::signed_transaction op_trx; - fc::raw::unpack(ss_trx, op_trx, 1000); - - fc::flat_map account_auths; - uint32_t total_weight = 0; - for (const auto &wallet_son : wallet_sons) { - total_weight = total_weight + wallet_son.weight; - account_auths[wallet_son.sidechain_public_keys.at(sidechain)] = wallet_son.weight; - } - - std::string memo_key = node_rpc_client->get_account_memo_key("son-account"); - - hive::authority active; - active.weight_threshold = total_weight * 2 / 3 + 1; - active.account_auths = account_auths; - - hive::account_update_operation auo; - auo.account = "son-account"; - auo.active = active; - auo.memo_key = op_trx.operations[0].get().memo_key; - - hive::signed_transaction htrx; - htrx.ref_block_num = op_trx.ref_block_num; - htrx.ref_block_prefix = op_trx.ref_block_prefix; - htrx.set_expiration(op_trx.expiration); - - htrx.operations.push_back(auo); - - std::stringstream ss; - fc::raw::pack(ss, htrx, 1000); - tx_str = boost::algorithm::hex(ss.str()); - } - } - - transaction_ok = (op_tx_str == tx_str); - } - } else { - transaction_ok = true; - } - } - - should_approve = address_ok && - transaction_ok; - break; - } - - case chain::operation::tag::value: { - bool process_ok = false; - son_wallet_deposit_id_type swdo_id = op_obj_idx_0.get().son_wallet_deposit_id; - const auto &idx = database.get_index_type().indices().get(); - const auto swdo = idx.find(swdo_id); - if (swdo != idx.end()) { - - std::string swdo_txid = swdo->sidechain_transaction_id; - std::string swdo_sidechain_from = swdo->sidechain_from; - std::string swdo_sidechain_currency = swdo->sidechain_currency; - uint64_t swdo_sidechain_amount = swdo->sidechain_amount.value; - uint64_t swdo_op_idx = std::stoll(swdo->sidechain_uid.substr(swdo->sidechain_uid.find_last_of("-"))); - - std::string tx_str = node_rpc_client->account_history_api_get_transaction(swdo_txid); - if (tx_str != "") { - - std::stringstream ss_tx(tx_str); - boost::property_tree::ptree tx; - boost::property_tree::read_json(ss_tx, tx); - - uint64_t op_idx = -1; - for (const auto &ops : tx.get_child("result.operations")) { - const auto &op = ops.second; - op_idx = op_idx + 1; - if (op_idx == swdo_op_idx) { - std::string operation_type = op.get("type"); - - if (operation_type == "transfer_operation") { - const auto &op_value = op.get_child("value"); - - std::string sidechain_from = op_value.get("from"); - - const auto &amount_child = op_value.get_child("amount"); - - uint64_t amount = amount_child.get("amount"); - std::string nai = amount_child.get("nai"); - std::string sidechain_currency = ""; - if ((nai == "@@000000013" /*?? HBD*/) || (nai == "@@000000013" /*TBD*/)) { - sidechain_currency = "HBD"; - } - if ((nai == "@@000000021") /*?? HIVE*/ || (nai == "@@000000021" /*TESTS*/)) { - sidechain_currency = "HIVE"; - } - - std::string memo = op_value.get("memo"); - boost::trim(memo); - if (!memo.empty()) { - sidechain_from = memo; - } - - process_ok = (swdo_sidechain_from == sidechain_from) && - (swdo_sidechain_currency == sidechain_currency) && - (swdo_sidechain_amount == amount); - } - } - } - } - } - should_approve = process_ok; - break; - } - - case chain::operation::tag::value: { - bool process_ok = false; - bool transaction_ok = false; - son_wallet_withdraw_id_type swwo_id = op_obj_idx_0.get().son_wallet_withdraw_id; - const auto &idx = database.get_index_type().indices().get(); - const auto swwo = idx.find(swwo_id); - if (swwo != idx.end()) { - - uint32_t swwo_block_num = swwo->block_num; - std::string swwo_peerplays_transaction_id = swwo->peerplays_transaction_id; - uint32_t swwo_op_idx = std::stoll(swwo->peerplays_uid.substr(swwo->peerplays_uid.find_last_of("-") + 1)); - - const auto &block = database.fetch_block_by_number(swwo_block_num); - - for (const auto &tx : block->transactions) { - if (tx.id().str() == swwo_peerplays_transaction_id) { - operation op = tx.operations[swwo_op_idx]; - transfer_operation t_op = op.get(); - - price asset_price = database.get(t_op.amount.asset_id).options.core_exchange_rate; - asset peerplays_asset = asset(t_op.amount.amount * asset_price.base.amount / asset_price.quote.amount); - - process_ok = (t_op.to == gpo.parameters.son_account()) && - (swwo->peerplays_from == t_op.from) && - (swwo->peerplays_asset == peerplays_asset); - break; - } - } - - object_id_type object_id = op_obj_idx_1.get().object_id; - std::string op_tx_str = op_obj_idx_1.get().transaction; - - const auto &st_idx = database.get_index_type().indices().get(); - const auto st = st_idx.find(object_id); - if (st == st_idx.end()) { - - std::string tx_str = ""; - - if (object_id.is()) { - const auto &idx = database.get_index_type().indices().get(); - const auto swwo = idx.find(object_id); - if (swwo != idx.end()) { - - std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str)); - hive::signed_transaction op_trx; - fc::raw::unpack(ss_trx, op_trx, 1000); - - uint64_t symbol = 0; - if (swwo->withdraw_currency == "HBD") { - symbol = hive::asset::hbd_symbol_ser; - } - if (swwo->withdraw_currency == "HIVE") { - symbol = hive::asset::hive_symbol_ser; - } - - hive::transfer_operation t_op; - t_op.from = "son-account"; - t_op.to = swwo->withdraw_address; - t_op.amount.amount = swwo->withdraw_amount; - t_op.amount.symbol = symbol; - t_op.memo = ""; - - hive::signed_transaction htrx; - htrx.ref_block_num = op_trx.ref_block_num; - htrx.ref_block_prefix = op_trx.ref_block_prefix; - htrx.set_expiration(op_trx.expiration); - - htrx.operations.push_back(t_op); - - std::stringstream ss; - fc::raw::pack(ss, htrx, 1000); - tx_str = boost::algorithm::hex(ss.str()); - } - } - - transaction_ok = (op_tx_str == tx_str); - } - } - - should_approve = process_ok && - transaction_ok; - break; - } - - case chain::operation::tag::value: { - should_approve = true; - son_id_type signer = op_obj_idx_0.get().signer; - std::string signature = op_obj_idx_0.get().signature; - sidechain_transaction_id_type sidechain_transaction_id = op_obj_idx_0.get().sidechain_transaction_id; - const auto &st_idx = database.get_index_type().indices().get(); - const auto sto = st_idx.find(sidechain_transaction_id); - if (sto == st_idx.end()) { - should_approve = false; - break; - } - - const auto &s_idx = database.get_index_type().indices().get(); - const auto son = s_idx.find(signer); - if (son == s_idx.end()) { - should_approve = false; - break; - } - - break; - } - - case chain::operation::tag::value: { - should_approve = true; - break; - } - - default: - should_approve = false; - elog("=================================================="); - elog("Proposal not considered for approval ${po}", ("po", po)); - elog("=================================================="); - } - - return should_approve; -} - -void sidechain_net_handler_hive::process_primary_wallet() { - const auto &swi = database.get_index_type().indices().get(); - const auto &active_sw = swi.rbegin(); - if (active_sw != swi.rend()) { - - if ((active_sw->addresses.find(sidechain) == active_sw->addresses.end()) || - (active_sw->addresses.at(sidechain).empty())) { - - if (proposal_exists(chain::operation::tag::value, active_sw->id)) { - return; - } - - const chain::global_property_object &gpo = database.get_global_properties(); - - auto active_sons = gpo.active_sons; - fc::flat_map account_auths; - uint32_t total_weight = 0; - for (const auto &active_son : active_sons) { - total_weight = total_weight + active_son.weight; - account_auths[active_son.sidechain_public_keys.at(sidechain)] = active_son.weight; - } - - std::string memo_key = node_rpc_client->get_account_memo_key("son-account"); - - if (memo_key.empty()) { - return; - } - - hive::authority active; - active.weight_threshold = total_weight * 2 / 3 + 1; - active.account_auths = account_auths; - - hive::account_update_operation auo; - auo.account = "son-account"; - auo.active = active; - auo.memo_key = hive::public_key_type(memo_key); - - std::string block_id_str = node_rpc_client->get_head_block_id(); - hive::block_id_type head_block_id(block_id_str); - - std::string head_block_time_str = node_rpc_client->get_head_block_time(); - time_point head_block_time = fc::time_point_sec::from_iso_string(head_block_time_str); - - hive::signed_transaction htrx; - htrx.set_reference_block(head_block_id); - htrx.set_expiration(head_block_time + fc::seconds(180)); - - htrx.operations.push_back(auo); - - std::stringstream ss; - fc::raw::pack(ss, htrx, 1000); - std::string tx_str = boost::algorithm::hex(ss.str()); - if (tx_str.empty()) { - return; - } - - proposal_create_operation proposal_op; - proposal_op.fee_paying_account = plugin.get_current_son_object().son_account; - uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3; - proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime); - - son_wallet_update_operation swu_op; - swu_op.payer = gpo.parameters.son_account(); - swu_op.son_wallet_id = active_sw->id; - swu_op.sidechain = sidechain; - swu_op.address = "son-account"; - - proposal_op.proposed_ops.emplace_back(swu_op); - - sidechain_transaction_create_operation stc_op; - stc_op.payer = gpo.parameters.son_account(); - stc_op.object_id = active_sw->id; - stc_op.sidechain = sidechain; - stc_op.transaction = tx_str; - stc_op.signers = gpo.active_sons; - - proposal_op.proposed_ops.emplace_back(stc_op); - - signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op); - try { - trx.validate(); - 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)); - } catch (fc::exception &e) { - elog("Sending proposal for son wallet update operation failed with exception ${e}", ("e", e.what())); - return; - } - } - } -} - -void sidechain_net_handler_hive::process_sidechain_addresses() { - const auto &sidechain_addresses_idx = database.get_index_type(); - const auto &sidechain_addresses_by_sidechain_idx = sidechain_addresses_idx.indices().get(); - 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; - op.payer = plugin.get_current_son_object().son_account; - op.sidechain_address_id = sao.id; - op.sidechain_address_account = sao.sidechain_address_account; - op.sidechain = sao.sidechain; - op.deposit_public_key = sao.deposit_public_key; - op.deposit_address = sao.withdraw_address; - op.deposit_address_data = sao.withdraw_address; - op.withdraw_public_key = sao.withdraw_public_key; - op.withdraw_address = sao.withdraw_address; - - signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op); - try { - trx.validate(); - 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)); - retval = true; - } catch (fc::exception &e) { - elog("Sending transaction for sidechain address update operation failed with exception ${e}", ("e", e.what())); - retval = false; - } - } - } - return retval; - }); -} - -bool sidechain_net_handler_hive::process_deposit(const son_wallet_deposit_object &swdo) { - const chain::global_property_object &gpo = database.get_global_properties(); - - price asset_price; - asset asset_to_issue; - if (swdo.sidechain_currency == "HBD") { - asset_price = database.get(database.get_global_properties().parameters.hbd_asset()).options.core_exchange_rate; - asset_to_issue = asset(swdo.peerplays_asset.amount * asset_price.quote.amount / asset_price.base.amount, database.get_global_properties().parameters.hbd_asset()); - } - if (swdo.sidechain_currency == "HIVE") { - asset_price = database.get(database.get_global_properties().parameters.hive_asset()).options.core_exchange_rate; - asset_to_issue = asset(swdo.peerplays_asset.amount * asset_price.quote.amount / asset_price.base.amount, database.get_global_properties().parameters.hive_asset()); - } - - proposal_create_operation proposal_op; - proposal_op.fee_paying_account = plugin.get_current_son_object().son_account; - uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3; - proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime); - - son_wallet_deposit_process_operation swdp_op; - swdp_op.payer = gpo.parameters.son_account(); - swdp_op.son_wallet_deposit_id = swdo.id; - proposal_op.proposed_ops.emplace_back(swdp_op); - - asset_issue_operation ai_op; - ai_op.fee = asset(2001000); - ai_op.issuer = gpo.parameters.son_account(); - ai_op.asset_to_issue = asset_to_issue; - ai_op.issue_to_account = swdo.peerplays_from; - proposal_op.proposed_ops.emplace_back(ai_op); - - signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op); - try { - trx.validate(); - 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; - } catch (fc::exception &e) { - elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what())); - return false; - } - - return false; -} - -bool sidechain_net_handler_hive::process_withdrawal(const son_wallet_withdraw_object &swwo) { - const chain::global_property_object &gpo = database.get_global_properties(); - - //===== - - uint64_t symbol = 0; - if (swwo.withdraw_currency == "HBD") { - symbol = hive::asset::hbd_symbol_ser; - } - if (swwo.withdraw_currency == "HIVE") { - symbol = hive::asset::hive_symbol_ser; - } - - hive::transfer_operation t_op; - t_op.from = "son-account"; - t_op.to = swwo.withdraw_address; - t_op.amount.amount = swwo.withdraw_amount; - t_op.amount.symbol = symbol; - t_op.memo = ""; - - std::string block_id_str = node_rpc_client->get_head_block_id(); - hive::block_id_type head_block_id(block_id_str); - - std::string head_block_time_str = node_rpc_client->get_head_block_time(); - time_point head_block_time = fc::time_point_sec::from_iso_string(head_block_time_str); - - hive::signed_transaction htrx; - htrx.set_reference_block(head_block_id); - htrx.set_expiration(head_block_time + fc::seconds(180)); - - htrx.operations.push_back(t_op); - - std::stringstream ss; - fc::raw::pack(ss, htrx, 1000); - std::string tx_str = boost::algorithm::hex(ss.str()); - if (tx_str.empty()) { - return false; - } - - //===== - - proposal_create_operation proposal_op; - proposal_op.fee_paying_account = plugin.get_current_son_object().son_account; - uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3; - proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime); - - son_wallet_withdraw_process_operation swwp_op; - swwp_op.payer = gpo.parameters.son_account(); - swwp_op.son_wallet_withdraw_id = swwo.id; - proposal_op.proposed_ops.emplace_back(swwp_op); - - sidechain_transaction_create_operation stc_op; - stc_op.payer = gpo.parameters.son_account(); - stc_op.object_id = swwo.id; - stc_op.sidechain = sidechain; - stc_op.transaction = tx_str; - stc_op.signers = gpo.active_sons; - proposal_op.proposed_ops.emplace_back(stc_op); - - signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op); - try { - trx.validate(); - 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; - } catch (fc::exception &e) { - elog("Sending proposal for withdraw sidechain transaction create operation failed with exception ${e}", ("e", e.what())); - return false; - } - - return false; -} - -std::string sidechain_net_handler_hive::process_sidechain_transaction(const sidechain_transaction_object &sto) { - std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction)); - hive::signed_transaction htrx; - fc::raw::unpack(ss_trx, htrx, 1000); - - std::string chain_id_str = node_rpc_client->get_chain_id(); - const hive::chain_id_type chain_id(chain_id_str); - - fc::optional privkey = graphene::utilities::wif_to_key(get_private_key(plugin.get_current_son_object().sidechain_public_keys.at(sidechain))); - signature_type st = htrx.sign(*privkey, chain_id); - - std::stringstream ss_st; - fc::raw::pack(ss_st, st, 1000); - std::string st_str = boost::algorithm::hex(ss_st.str()); - - return st_str; -} - -std::string sidechain_net_handler_hive::send_sidechain_transaction(const sidechain_transaction_object &sto) { - std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction)); - hive::signed_transaction htrx; - fc::raw::unpack(ss_trx, htrx, 1000); - - for (auto signature : sto.signatures) { - if (!signature.second.empty()) { - std::stringstream ss_st(boost::algorithm::unhex(signature.second)); - signature_type st; - fc::raw::unpack(ss_st, st, 1000); - htrx.signatures.push_back(st); - } - } - - std::string params = fc::json::to_string(htrx); - node_rpc_client->network_broadcast_api_broadcast_transaction(params); - - return htrx.id().str(); -} - -bool sidechain_net_handler_hive::settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) { - if (sto.object_id.is()) { - settle_amount.amount = 0; - return true; - } - - if (sto.sidechain_transaction.empty()) { - return false; - } - - std::string tx_str = node_rpc_client->account_history_api_get_transaction(sto.sidechain_transaction); - if (tx_str != "") { - - std::stringstream ss_tx(tx_str); - boost::property_tree::ptree tx_json; - boost::property_tree::read_json(ss_tx, tx_json); - - //const chain::global_property_object &gpo = database.get_global_properties(); - - std::string tx_txid = tx_json.get("result.transaction_id"); - uint32_t tx_block_num = tx_json.get("result.block_num"); - uint32_t last_irreversible_block = std::stoul(node_rpc_client->get_last_irreversible_block_num()); - - //std::string tx_address = addr.get_address(); - //int64_t tx_amount = -1; - - if (tx_block_num <= last_irreversible_block) { - if (sto.object_id.is()) { - auto swwo = database.get(sto.object_id); - if (swwo.withdraw_currency == "HBD") { - settle_amount = asset(swwo.withdraw_amount, database.get_global_properties().parameters.hbd_asset()); - } - if (swwo.withdraw_currency == "HIVE") { - settle_amount = asset(swwo.withdraw_amount, database.get_global_properties().parameters.hive_asset()); - } - return true; - } - } - } - return false; -} - -void sidechain_net_handler_hive::schedule_hive_listener() { - fc::time_point now = fc::time_point::now(); - int64_t time_to_next = 1000; - - fc::time_point next_wakeup(now + fc::milliseconds(time_to_next)); - - _listener_task = fc::schedule([this] { - hive_listener_loop(); - }, - next_wakeup, "SON Hive listener task"); -} - -void sidechain_net_handler_hive::hive_listener_loop() { - schedule_hive_listener(); - - std::string reply = node_rpc_client->database_api_get_dynamic_global_properties(); - if (!reply.empty()) { - std::stringstream ss(reply); - boost::property_tree::ptree json; - boost::property_tree::read_json(ss, json); - if (json.count("result")) { - uint64_t head_block_number = json.get("result.head_block_number"); - if (head_block_number != last_block_received) { - std::string event_data = std::to_string(head_block_number); - handle_event(event_data); - last_block_received = head_block_number; - } - } - } - - //std::string reply = node_rpc_client->get_last_irreversible_block_num(); - //if (!reply.empty()) { - // uint64_t last_irreversible_block = std::stoul(reply); - // if (last_irreversible_block != last_block_received) { - // std::string event_data = std::to_string(last_irreversible_block); - // handle_event(event_data); - // last_block_received = last_irreversible_block; - // } - //} -} - -void sidechain_net_handler_hive::handle_event(const std::string &event_data) { - std::string block = node_rpc_client->block_api_get_block(std::atoll(event_data.c_str())); - if (block != "") { - std::stringstream ss(block); - boost::property_tree::ptree block_json; - boost::property_tree::read_json(ss, block_json); - - size_t tx_idx = -1; - for (const auto &tx_ids_child : block_json.get_child("result.block.transactions")) { - boost::property_tree::ptree tx = tx_ids_child.second; - tx_idx = tx_idx + 1; - - size_t op_idx = -1; - for (const auto &ops : tx.get_child("operations")) { - const auto &op = ops.second; - op_idx = op_idx + 1; - - std::string operation_type = op.get("type"); - - if (operation_type == "transfer_operation") { - const auto &op_value = op.get_child("value"); - - std::string from = op_value.get("from"); - std::string to = op_value.get("to"); - - if (to == "son-account") { - - const auto &amount_child = op_value.get_child("amount"); - - uint64_t amount = amount_child.get("amount"); - //uint64_t precision = amount_child.get("precision"); - std::string nai = amount_child.get("nai"); - std::string sidechain_currency = ""; - price sidechain_currency_price = {}; - if ((nai == "@@000000013" /*?? HBD*/) || (nai == "@@000000013" /*TBD*/)) { - sidechain_currency = "HBD"; - sidechain_currency_price = database.get(database.get_global_properties().parameters.hbd_asset()).options.core_exchange_rate; - } - if ((nai == "@@000000021") /*?? HIVE*/ || (nai == "@@000000021" /*TESTS*/)) { - sidechain_currency = "HIVE"; - sidechain_currency_price = database.get(database.get_global_properties().parameters.hive_asset()).options.core_exchange_rate; - } - - std::string memo = op_value.get("memo"); - boost::trim(memo); - if (!memo.empty()) { - from = memo; - } - - const auto &sidechain_addresses_idx = database.get_index_type().indices().get(); - const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, from, time_point_sec::maximum())); - account_id_type accn = account_id_type(); - if (addr_itr == sidechain_addresses_idx.end()) { - const auto &account_idx = database.get_index_type().indices().get(); - const auto &account_itr = account_idx.find(from); - if (account_itr == account_idx.end()) { - continue; - } else { - accn = account_itr->id; - } - } else { - accn = addr_itr->sidechain_address_account; - } - - std::vector transaction_ids; - for (const auto &tx_ids_child : block_json.get_child("result.block.transaction_ids")) { - const auto &transaction_id = tx_ids_child.second.get_value(); - transaction_ids.push_back(transaction_id); - } - std::string transaction_id = transaction_ids.at(tx_idx); - - std::stringstream ss; - ss << "hive" - << "-" << transaction_id << "-" << op_idx; - std::string sidechain_uid = ss.str(); - - sidechain_event_data sed; - sed.timestamp = database.head_block_time(); - sed.block_num = database.head_block_num(); - sed.sidechain = sidechain; - sed.sidechain_uid = sidechain_uid; - sed.sidechain_transaction_id = transaction_id; - sed.sidechain_from = from; - sed.sidechain_to = to; - sed.sidechain_currency = sidechain_currency; - sed.sidechain_amount = amount; - sed.peerplays_from = accn; - sed.peerplays_to = database.get_global_properties().parameters.son_account(); - sed.peerplays_asset = asset(sed.sidechain_amount * sidechain_currency_price.base.amount / sidechain_currency_price.quote.amount); - sidechain_event_data_received(sed); - } - } - } - } - } -} - -}} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp index d5a9ec32..ecf3cc00 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp @@ -25,15 +25,6 @@ namespace graphene { namespace peerplays_sidechain { sidechain_net_handler_peerplays::sidechain_net_handler_peerplays(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) : sidechain_net_handler(_plugin, options) { sidechain = sidechain_type::peerplays; - //const auto &assets_by_symbol = database.get_index_type().indices().get(); - //const auto get_asset_id = [&assets_by_symbol](const string &symbol) { - // auto asset_itr = assets_by_symbol.find(symbol); - // FC_ASSERT(asset_itr != assets_by_symbol.end(), "Unable to find asset '${sym}'", ("sym", symbol)); - // return asset_itr->get_id(); - //}; - //tracked_assets.push_back(get_asset_id("PBTC")); - //tracked_assets.push_back(get_asset_id("PETH")); - //tracked_assets.push_back(get_asset_id("PEOS")); if (options.count("peerplays-private-key")) { const std::vector pub_priv_keys = options["peerplays-private-key"].as>(); @@ -46,6 +37,10 @@ sidechain_net_handler_peerplays::sidechain_net_handler_peerplays(peerplays_sidec private_keys[key_pair.first] = key_pair.second; } } + + database.applied_block.connect([&](const signed_block &b) { + on_applied_block(b); + }); } sidechain_net_handler_peerplays::~sidechain_net_handler_peerplays() { @@ -136,34 +131,32 @@ 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; - op.payer = plugin.get_current_son_object().son_account; - op.sidechain_address_id = sao.id; - op.sidechain_address_account = sao.sidechain_address_account; - op.sidechain = sao.sidechain; - op.deposit_public_key = sao.deposit_public_key; - op.deposit_address = sao.withdraw_address; - op.deposit_address_data = sao.withdraw_address; - op.withdraw_public_key = sao.withdraw_public_key; - op.withdraw_address = sao.withdraw_address; + op.payer = plugin.get_current_son_object().son_account; + op.sidechain_address_id = sao.id; + op.sidechain_address_account = sao.sidechain_address_account; + op.sidechain = sao.sidechain; + op.deposit_public_key = sao.deposit_public_key; + op.deposit_address = sao.withdraw_address; + op.deposit_address_data = sao.withdraw_address; + op.withdraw_public_key = sao.withdraw_public_key; + op.withdraw_address = sao.withdraw_address; - signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op); - try { - trx.validate(); - 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)); - retval = true; - } catch (fc::exception &e) { - elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what())); - retval = false; - } + signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op); + try { + trx.validate(); + 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; + } catch (fc::exception &e) { + elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what())); + return false; + } } } - return retval; }); return; } @@ -271,23 +264,45 @@ std::string sidechain_net_handler_peerplays::send_sidechain_transaction(const si return ""; } -bool sidechain_net_handler_peerplays::settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) { +int64_t sidechain_net_handler_peerplays::settle_sidechain_transaction(const sidechain_transaction_object &sto) { + int64_t settle_amount = 0; + return settle_amount; +} - if (sto.object_id.is()) { - settle_amount = asset(0); +void sidechain_net_handler_peerplays::on_applied_block(const signed_block &b) { + for (const auto &trx : b.transactions) { + size_t operation_index = -1; + for (auto op : trx.operations) { + operation_index = operation_index + 1; + if (op.which() == operation::tag::value) { + transfer_operation transfer_op = op.get(); + if (transfer_op.to != plugin.database().get_global_properties().parameters.son_account()) { + continue; + } + + std::stringstream ss; + ss << "peerplays" + << "-" << trx.id().str() << "-" << operation_index; + std::string sidechain_uid = ss.str(); + + sidechain_event_data sed; + sed.timestamp = database.head_block_time(); + sed.block_num = database.head_block_num(); + sed.sidechain = sidechain_type::peerplays; + sed.sidechain_uid = sidechain_uid; + sed.sidechain_transaction_id = trx.id().str(); + sed.sidechain_from = fc::to_string(transfer_op.from.space_id) + "." + fc::to_string(transfer_op.from.type_id) + "." + fc::to_string((uint64_t)transfer_op.from.instance); + sed.sidechain_to = fc::to_string(transfer_op.to.space_id) + "." + fc::to_string(transfer_op.to.type_id) + "." + fc::to_string((uint64_t)transfer_op.to.instance); + sed.sidechain_currency = fc::to_string(transfer_op.amount.asset_id.space_id) + "." + fc::to_string(transfer_op.amount.asset_id.type_id) + "." + fc::to_string((uint64_t)transfer_op.amount.asset_id.instance); + sed.sidechain_amount = transfer_op.amount.amount; + sed.peerplays_from = transfer_op.from; + sed.peerplays_to = transfer_op.to; + price asset_price = database.get(transfer_op.amount.asset_id).options.core_exchange_rate; + sed.peerplays_asset = asset(transfer_op.amount.amount * asset_price.base.amount / asset_price.quote.amount); + sidechain_event_data_received(sed); + } + } } - - if (sto.object_id.is()) { - //auto swdo = database.get(sto.object_id); - //settle_amount = asset(swdo.sidechain_amount, swdo.sidechain_currency); - } - - if (sto.object_id.is()) { - auto swwo = database.get(sto.object_id); - settle_amount = swwo.peerplays_asset; - } - - return true; } }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp index ff876b0c..962488a6 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include namespace graphene { namespace peerplays_sidechain { @@ -11,10 +10,6 @@ namespace graphene { namespace peerplays_sidechain { sidechain_net_manager::sidechain_net_manager(peerplays_sidechain_plugin &_plugin) : plugin(_plugin), database(_plugin.database()) { - - //database.applied_block.connect([&](const signed_block &b) { - // on_applied_block(b); - //}); } sidechain_net_manager::~sidechain_net_manager() { @@ -31,12 +26,6 @@ bool sidechain_net_manager::create_handler(sidechain_type sidechain, const boost ret_val = true; break; } - case sidechain_type::hive: { - std::unique_ptr h = std::unique_ptr(new sidechain_net_handler_hive(plugin, options)); - net_handlers.push_back(std::move(h)); - ret_val = true; - break; - } case sidechain_type::peerplays: { std::unique_ptr h = std::unique_ptr(new sidechain_net_handler_peerplays(plugin, options)); net_handlers.push_back(std::move(h)); @@ -98,7 +87,4 @@ void sidechain_net_manager::settle_sidechain_transactions() { } } -void sidechain_net_manager::on_applied_block(const signed_block &b) { -} - }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/snapshot/CMakeLists.txt b/libraries/plugins/snapshot/CMakeLists.txt index 57fb1689..728740de 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 PRIVATE graphene_plugin ) +target_link_libraries( graphene_snapshot graphene_chain graphene_app ) 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 a4272b2d..95759bbf 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 PRIVATE graphene_plugin ) +target_link_libraries( graphene_witness graphene_chain graphene_app ) 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 d535ca3b..1e7a9d6e 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -91,10 +91,8 @@ 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")) { - vector v = fc::json::from_string(options.at("witness-ids").as()).as>( 5 ); - _witnesses.insert(v.begin(), v.end()); - } + if (options.count("witness-ids")) + boost::insert(_witnesses, fc::json::from_string(options.at("witness-ids").as()).as>( 5 )); if( options.count("private-key") ) { diff --git a/libraries/wallet/CMakeLists.txt b/libraries/wallet/CMakeLists.txt index d3825810..8c9f8790 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 ) +target_link_libraries( graphene_wallet PRIVATE graphene_app graphene_net graphene_chain graphene_utilities fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) 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 a7921b1f..ac7d8996 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -62,18 +62,13 @@ 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 { @@ -318,7 +313,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 */ @@ -330,14 +325,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 @@ -345,7 +340,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. * @@ -356,12 +351,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; @@ -397,7 +392,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 @@ -453,8 +448,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 @@ -462,7 +457,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. * @@ -538,21 +533,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. @@ -560,7 +555,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 @@ -573,7 +568,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(); @@ -608,13 +603,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 @@ -652,7 +647,7 @@ class wallet_api * @see suggest_brain_key() * * @param brain_key Brain key - * @param number_of_desired_keys Number of desired keys + * @param numberOfDesiredKeys Number of desired keys * @return A list of keys that are deterministically derived from the brainkey */ vector derive_owner_keys_from_brain_key(string brain_key, int number_of_desired_keys = 1) const; @@ -667,12 +662,7 @@ class wallet_api bool is_public_key_registered(string public_key) const; /** - * Gets private key from password - * - * @param account Account name - * @param role Account role - active | owner | memo - * @param password Account password - * @return public/private key pair + * @param role - active | owner | memo */ pair get_private_key_from_password( string account, string role, string password )const; @@ -688,7 +678,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() * @@ -751,41 +741,6 @@ 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'. @@ -826,7 +781,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 @@ -900,33 +855,27 @@ class wallet_api * that it exists in the blockchain. If it exists then it will report the amount received and * who sent it. * - * @param confirmation_receipt - a base58 encoded stealth confirmation - * @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 opt_memo - optional memo + * @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 */ blind_receipt receive_blind_transfer( string confirmation_receipt, string opt_from, string opt_memo ); /** - * Transfers a public balance from from_account_id_or_name to one or more blinded balances using a + * Transfers a public balance from @from to one or more blinded balances using a * stealth transfer. - * - * @param from_account_id_or_name account id or name - * @param asset_symbol asset symbol - * @param to_amounts map from key or label to amount - * @param broadcast true to broadcast the transaction on the network - * @returns blind confirmation structure */ - 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, - vector> to_amounts, + /** map from key or label to amount */ + 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 ); @@ -942,14 +891,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. * @@ -962,16 +911,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 @@ -988,12 +937,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 @@ -1003,7 +952,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, @@ -1011,7 +960,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 @@ -1021,11 +970,11 @@ class wallet_api * * @param buyer_account The account buying the asset for another asset. * @param base The name or id of the asset to buy. - * @param quote The name or id of the asset being offered as payment. + * @param quote The name or id of the assest being offered as payment. * @param rate The rate in base:quote at which you want to buy. * @param amount the amount of base you want to buy. * @param broadcast true to broadcast the transaction on the network. - * @returns The signed transaction buying the funds. + * @param The signed transaction selling the funds. */ signed_transaction buy( string buyer_account, string base, @@ -1066,14 +1015,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 @@ -1093,7 +1042,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. @@ -1111,8 +1060,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, @@ -1176,7 +1125,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 @@ -1204,7 +1153,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). * @@ -1245,7 +1194,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 @@ -1313,7 +1262,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. @@ -1324,7 +1273,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 @@ -1339,7 +1288,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 @@ -1478,12 +1427,6 @@ class wallet_api */ map list_active_sons(); - /** - * @brief Get SON network status - * @return SON network status description - */ - map get_son_network_status(); - /** * @brief Get active SON wallet * @return Active SON wallet object @@ -1511,7 +1454,6 @@ class wallet_api * @param account the name or id of the account who owns the address * @param sidechain a sidechain to whom address belongs * @param deposit_public_key sidechain public key used for deposit address - * @param deposit_address sidechain address for deposits * @param withdraw_public_key sidechain public key used for withdraw address * @param withdraw_address sidechain address for withdrawals * @param broadcast true to broadcast the transaction on the network @@ -1520,7 +1462,6 @@ class wallet_api signed_transaction add_sidechain_address(string account, sidechain_type sidechain, string deposit_public_key, - string deposit_address, string withdraw_public_key, string withdraw_address, bool broadcast = false); @@ -1581,7 +1522,7 @@ class wallet_api /** * Update a witness object owned by the given account. * - * @param witness_name The name of the witness's owner account. Also accepts the ID of the owner account or the ID of the witness. + * @param witness The name of the witness's owner account. Also accepts the ID of the owner account or the ID of the witness. * @param url Same as for create_witness. The empty string makes it remain the same. * @param block_signing_key The new block signing public key. The empty string makes it remain the same. * @param broadcast true if you wish to broadcast the transaction. @@ -1619,7 +1560,7 @@ class wallet_api * Update your votes for a worker * * @param account The account which will pay the fee and update votes. - * @param delta {"vote_for" : [...], "vote_against" : [...], "vote_abstain" : [...]} + * @param worker_vote_delta {"vote_for" : [...], "vote_against" : [...], "vote_abstain" : [...]} * @param broadcast true if you wish to broadcast the transaction. */ signed_transaction update_worker_votes( @@ -1680,7 +1621,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. @@ -1690,7 +1631,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 @@ -1752,12 +1693,12 @@ class wallet_api signed_transaction update_son_votes(string voting_account, std::vector sons_to_approve, std::vector sons_to_reject, - uint16_t desired_number_of_sons, + uint16_t desired_number_of_son, bool broadcast = false); /** 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. @@ -1767,7 +1708,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 @@ -1779,12 +1720,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 @@ -1799,7 +1740,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 @@ -1830,24 +1771,24 @@ 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 desired_number_of_witnesses desired number of witnesses - * @param desired_number_of_committee_members desired number of committee members + * @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 */ @@ -1899,16 +1840,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 @@ -1933,7 +1874,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. @@ -2014,7 +1955,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, @@ -2041,7 +1982,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, @@ -2112,7 +2053,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 @@ -2149,7 +2090,6 @@ class wallet_api /** Creates a new tournament * @param creator the accout that is paying the fee to create the tournament * @param options the options detailing the specifics of the tournament - * @param broadcast true if you wish to broadcast the transaction * @return the signed version of the transaction */ signed_transaction tournament_create( string creator, tournament_options options, bool broadcast = false ); @@ -2189,7 +2129,7 @@ class wallet_api tournament_state state); /** Get specific information about a tournament - * @param id the ID of the tournament + * @param tournament_id the ID of the tournament */ tournament_object get_tournament(tournament_id_type id); @@ -2197,7 +2137,6 @@ class wallet_api * @param game_id the id of the game * @param player_account the name of the player * @param gesture rock, paper, or scissors - * @param broadcast true if you wish to broadcast the transaction * @return the signed version of the transaction */ signed_transaction rps_throw(game_id_type game_id, @@ -2236,7 +2175,6 @@ 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 // ///////// @@ -2250,9 +2188,6 @@ class wallet_api * @param revenue_split revenue split for the sale * @param is_transferable can transfer the NFT or not * @param is_sellable can sell NFT or not - * @param role_id account role id - * @param max_supply max supply of NTFs - * @param lottery_options lottery options * @param broadcast true to broadcast transaction to the network * @return Signed transaction transfering the funds */ @@ -2265,8 +2200,6 @@ class wallet_api bool is_transferable, bool is_sellable, optional role_id, - optional max_supply, - optional lottery_options, bool broadcast); /** @@ -2280,7 +2213,6 @@ class wallet_api * @param revenue_split revenue split for the sale * @param is_transferable can transfer the NFT or not * @param is_sellable can sell NFT or not - * @param role_id account role id * @param broadcast true to broadcast transaction to the network * @return Signed transaction transfering the funds */ @@ -2394,8 +2326,8 @@ class wallet_api /** * @brief Returns operator approved state for all NFT owned by owner - * @param owner_account_id_or_name NFT owner account ID or name - * @param operator_account_id_or_name NFT operator account ID or name + * @param owner NFT owner account ID + * @param token_id NFT ID * @return True if operator is approved for all NFT owned by owner, else False */ bool nft_is_approved_for_all(string owner_account_id_or_name, string operator_account_id_or_name) const; @@ -2405,7 +2337,6 @@ 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, @@ -2516,8 +2447,6 @@ 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) ) @@ -2546,7 +2475,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, @@ -2581,8 +2510,6 @@ 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) @@ -2624,7 +2551,6 @@ FC_API( graphene::wallet::wallet_api, (update_son_vesting_balances) (list_sons) (list_active_sons) - (get_son_network_status) (request_son_maintenance) (cancel_request_son_maintenance) (get_active_son_wallet) @@ -2743,7 +2669,6 @@ 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 e876924e..7d4eb9f8 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(); @@ -734,16 +734,12 @@ public: { return _remote_db->get_dynamic_global_properties(); } - std::string object_id_to_string(object_id_type id) const - { - std::string object_id = fc::to_string(id.space()) - + "." + fc::to_string(id.type()) - + "." + fc::to_string(id.instance()); - return object_id; - } std::string account_id_to_string(account_id_type id) const { - return object_id_to_string(id); + std::string account_id = fc::to_string(id.space_id) + + "." + fc::to_string(id.type_id) + + "." + fc::to_string(id.instance.value); + return account_id; } account_object get_account(account_id_type id) const { @@ -913,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]; @@ -933,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; @@ -976,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 { @@ -1133,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) ); } @@ -1339,102 +1335,6 @@ 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() ); @@ -1629,7 +1529,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 ); @@ -1640,7 +1540,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); @@ -1648,8 +1548,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, @@ -2207,40 +2107,6 @@ public: return result; } FC_CAPTURE_AND_RETHROW() } - map get_son_network_status() - { try { - global_property_object gpo = get_global_properties(); - vector son_ids; - son_ids.reserve(gpo.active_sons.size()); - std::transform(gpo.active_sons.begin(), gpo.active_sons.end(), - std::inserter(son_ids, son_ids.end()), - [](const son_info& swi) { - return swi.son_id; - }); - - map result; - std::vector> son_objects = _remote_db->get_sons(son_ids); - for(auto son_obj: son_objects) { - string status; - if (son_obj) { - son_statistics_object sso = get_object(son_obj->statistics); - if (sso.last_active_timestamp + fc::seconds(gpo.parameters.son_heartbeat_frequency()) > time_point::now()) { - status = "OK, regular SON heartbeat"; - } else { - if (sso.last_active_timestamp + fc::seconds(gpo.parameters.son_down_time()) > time_point::now()) { - status = "OK, irregular SON heartbeat, but not triggering SON down proposal"; - } else { - status = "NOT OK, irregular SON heartbeat, triggering SON down proposal"; - } - } - } else { - status = "NOT OK, invalid SON id"; - } - result[son_obj->id] = status; - } - return result; - } FC_CAPTURE_AND_RETHROW() } - optional get_active_son_wallet() { try { return _remote_db->get_active_son_wallet(); @@ -2259,7 +2125,6 @@ public: signed_transaction add_sidechain_address(string account, sidechain_type sidechain, string deposit_public_key, - string deposit_address, string withdraw_public_key, string withdraw_address, bool broadcast /* = false */) @@ -2271,7 +2136,6 @@ public: op.sidechain_address_account = sidechain_address_account_id; op.sidechain = sidechain; op.deposit_public_key = deposit_public_key; - op.deposit_address = deposit_address; op.withdraw_public_key = withdraw_public_key; op.withdraw_address = withdraw_address; @@ -2543,13 +2407,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)); } @@ -2592,14 +2456,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) { @@ -2629,7 +2493,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 { @@ -2656,7 +2520,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 @@ -2782,7 +2646,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 { @@ -2793,7 +2657,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)); @@ -2809,7 +2673,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 @@ -2827,7 +2691,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; @@ -3436,7 +3300,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; @@ -3450,7 +3314,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); @@ -4263,7 +4127,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); @@ -4411,7 +4275,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 ); } @@ -4419,7 +4283,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; @@ -4470,9 +4334,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 ) @@ -5081,11 +4945,6 @@ map wallet_api::list_active_sons() return my->list_active_sons(); } -map wallet_api::get_son_network_status() -{ - return my->get_son_network_status(); -} - optional wallet_api::get_active_son_wallet() { return my->get_active_son_wallet(); @@ -5104,12 +4963,11 @@ vector> wallet_api::get_son_wallets(uint32_t limit) signed_transaction wallet_api::add_sidechain_address(string account, sidechain_type sidechain, string deposit_public_key, - string deposit_address, string withdraw_public_key, string withdraw_address, bool broadcast /* = false */) { - return my->add_sidechain_address(account, sidechain, deposit_public_key, deposit_address, withdraw_public_key, withdraw_address, broadcast); + return my->add_sidechain_address(account, sidechain, deposit_public_key, withdraw_public_key, withdraw_address, broadcast); } signed_transaction wallet_api::delete_sidechain_address(string account, @@ -5738,25 +5596,6 @@ 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); @@ -5782,15 +5621,8 @@ signed_transaction wallet_api::sell( string seller_account, double amount, bool 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 ); + return my->sell_asset( seller_account, std::to_string( amount ), base, + std::to_string( rate * amount ), quote, 0, false, broadcast ); } signed_transaction wallet_api::buy( string buyer_account, @@ -5800,15 +5632,8 @@ signed_transaction wallet_api::buy( string buyer_account, double amount, bool 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 ); + return my->sell_asset( buyer_account, std::to_string( rate * amount ), quote, + std::to_string( amount ), base, 0, false, broadcast ); } signed_transaction wallet_api::borrow_asset(string seller_name, string amount_to_sell, @@ -6459,22 +6284,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); } @@ -6537,7 +6362,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, @@ -6546,22 +6371,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); } @@ -6946,10 +6771,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 ) { @@ -7031,7 +6856,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)); @@ -7078,8 +6903,6 @@ 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); @@ -7103,8 +6926,6 @@ 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); @@ -7288,21 +7109,6 @@ 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 d9c82346..ba73cdca 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory( build_helpers ) -if( BUILD_PEERPLAYS_PROGRAMS ) +if( BUILD_BITSHARES_PROGRAMS ) add_subdirectory( cli_wallet ) add_subdirectory( genesis_util ) add_subdirectory( witness_node ) @@ -7,4 +7,4 @@ if( BUILD_PEERPLAYS_PROGRAMS ) add_subdirectory( delayed_node ) add_subdirectory( js_operation_serializer ) add_subdirectory( size_checker ) -endif( BUILD_PEERPLAYS_PROGRAMS ) +endif( BUILD_BITSHARES_PROGRAMS ) diff --git a/programs/build_helpers/CMakeLists.txt b/programs/build_helpers/CMakeLists.txt index e6e92455..7a625b25 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 ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( cat-parts PRIVATE fc ${CMAKE_DL_LIBS} ${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 graphene_chain ${PLATFORM_SPECIFIC_LIBS} ) +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} ) diff --git a/programs/cli_wallet/CMakeLists.txt b/programs/cli_wallet/CMakeLists.txt index 31f697eb..140bdce3 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_egenesis_brief graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_net graphene_chain graphene_egenesis_brief graphene_utilities graphene_wallet fc ${CMAKE_DL_LIBS} ${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 e39ea929..232d265e 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_egenesis_full ${PLATFORM_SPECIFIC_LIBS} ) + 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} ) install( TARGETS debug_node diff --git a/programs/delayed_node/CMakeLists.txt b/programs/delayed_node/CMakeLists.txt index 7e610ace..4dbe2bbf 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_egenesis_full graphene_delayed_node ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_account_history graphene_market_history graphene_delayed_node graphene_chain graphene_egenesis_full fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS delayed_node diff --git a/programs/genesis_util/CMakeLists.txt b/programs/genesis_util/CMakeLists.txt index 80a3c7b8..9c3b278d 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_egenesis_none ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_chain graphene_egenesis_none fc ${CMAKE_DL_LIBS} ${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 ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_chain graphene_egenesis_none graphene_utilities fc ${CMAKE_DL_LIBS} ${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 ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/programs/js_operation_serializer/CMakeLists.txt b/programs/js_operation_serializer/CMakeLists.txt index a49d164e..dad8ded2 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 ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_net graphene_chain graphene_egenesis_none graphene_utilities graphene_wallet fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS js_operation_serializer diff --git a/programs/size_checker/CMakeLists.txt b/programs/size_checker/CMakeLists.txt index a1a504a3..5e0a167c 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 ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_chain graphene_egenesis_none fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS size_checker diff --git a/programs/witness_node/CMakeLists.txt b/programs/witness_node/CMakeLists.txt index 806330d6..d5578379 100644 --- a/programs/witness_node/CMakeLists.txt +++ b/programs/witness_node/CMakeLists.txt @@ -11,7 +11,7 @@ endif() # We have to link against graphene_debug_witness because deficiency in our API infrastructure doesn't allow plugins to be fully abstracted #246 target_link_libraries( witness_node - PRIVATE graphene_app graphene_egenesis_full graphene_snapshot graphene_witness peerplays_sidechain ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_account_history graphene_affiliate_stats graphene_elasticsearch graphene_market_history graphene_witness graphene_chain graphene_debug_witness graphene_bookie graphene_egenesis_full graphene_snapshot graphene_es_objects fc peerplays_sidechain ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) # also add dependencies to graphene_generate_genesis graphene_generate_uia_sharedrop_genesis if you want those plugins install( TARGETS diff --git a/programs/witness_node/genesis.json b/programs/witness_node/genesis.json index 1e0610f4..d38f3e4e 100644 --- a/programs/witness_node/genesis.json +++ b/programs/witness_node/genesis.json @@ -392,7 +392,7 @@ "son_deregister_time": 43200, "son_heartbeat_frequency": 180, "son_down_time": 360, - "maximum_son_count": 15 + "maximum_son_count": 7 } }, "initial_bts_accounts": [], diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6ff915a9..01474582 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,65 +1,62 @@ +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} ) -target_link_libraries( chain_test PRIVATE graphene_wallet graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} ) +target_link_libraries( chain_test graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_bookie graphene_egenesis_none fc graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( tests/serialization_tests.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) file(GLOB PERFORMANCE_TESTS "performance/*.cpp") -add_executable( performance_test ${PERFORMANCE_TESTS} ) -target_link_libraries( performance_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +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} ) file(GLOB BENCH_MARKS "benchmarks/*.cpp") -add_executable( chain_bench ${BENCH_MARKS} ) -target_link_libraries( chain_bench PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +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} ) file(GLOB APP_SOURCES "app/*.cpp") add_executable( app_test ${APP_SOURCES} ) -target_link_libraries( app_test PRIVATE graphene_tests_common graphene_witness ${PLATFORM_SPECIFIC_LIBS} ) +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} ) file(GLOB INTENSE_SOURCES "intense/*.cpp") -add_executable( intense_test ${INTENSE_SOURCES} ) -target_link_libraries( intense_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +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} ) file(GLOB BETTING_TESTS "betting/*.cpp") -add_executable( betting_test ${BETTING_TESTS} ) -target_link_libraries( betting_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( betting_test ${BETTING_TESTS} ${COMMON_SOURCES} ) +target_link_libraries( betting_test graphene_chain graphene_app graphene_account_history graphene_elasticsearch graphene_es_objects graphene_bookie graphene_egenesis_none fc graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB PEERPLAYS_SIDECHAIN_TESTS "peerplays_sidechain/*.cpp") -add_executable( peerplays_sidechain_test ${PEERPLAYS_SIDECHAIN_TESTS} ) -target_link_libraries( peerplays_sidechain_test PRIVATE graphene_tests_common peerplays_sidechain ${PLATFORM_SPECIFIC_LIBS} ) +add_executable( peerplays_sidechain_test ${PEERPLAYS_SIDECHAIN_TESTS} ${COMMON_SOURCES} ) +target_link_libraries( peerplays_sidechain_test graphene_chain graphene_app graphene_account_history graphene_bookie graphene_elasticsearch graphene_es_objects graphene_egenesis_none fc graphene_wallet ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB TOURNAMENT_TESTS "tournament/*.cpp") -add_executable( tournament_test ${TOURNAMENT_TESTS} ) -target_link_libraries( tournament_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +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} ) file(GLOB RANDOM_SOURCES "random/*.cpp") -add_executable( random_test ${RANDOM_SOURCES} ) -target_link_libraries( random_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) +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} ) 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 PRIVATE graphene_wallet graphene_tests_common graphene_witness ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( cli_test graphene_chain graphene_app graphene_witness graphene_wallet graphene_egenesis_none fc graphene_elasticsearch graphene_es_objects ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( cli/main.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) file(GLOB ES_SOURCES "elasticsearch/*.cpp") -add_executable( es_test ${ES_SOURCES} ) -target_link_libraries( es_test PRIVATE graphene_tests_common ) +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_subdirectory( generate_empty_blocks ) diff --git a/tests/betting/betting_tests.cpp b/tests/betting/betting_tests.cpp index 3898bb6c..cb6118a6 100644 --- a/tests/betting/betting_tests.cpp +++ b/tests/betting/betting_tests.cpp @@ -132,6 +132,114 @@ 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) @@ -201,12 +309,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() } @@ -224,23 +332,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 @@ -254,28 +362,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 @@ -289,20 +397,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() } @@ -319,19 +427,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); @@ -356,18 +464,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); @@ -390,19 +498,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); @@ -420,7 +528,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); @@ -442,7 +550,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); @@ -457,7 +565,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); @@ -479,7 +587,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); @@ -492,7 +600,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); } @@ -512,12 +620,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); @@ -547,7 +655,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); } @@ -567,7 +675,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); @@ -591,7 +699,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); } @@ -612,40 +720,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); @@ -666,11 +774,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; @@ -680,25 +788,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); @@ -730,16 +838,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); @@ -755,7 +863,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); } @@ -776,15 +884,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() @@ -808,21 +916,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() @@ -844,11 +952,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_id(db).get_status())); + idump((capitals_win_market.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}); @@ -857,7 +965,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}); @@ -866,7 +974,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 @@ -877,11 +985,17 @@ 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}}); + 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; generate_blocks(1); @@ -935,19 +1049,25 @@ 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_id(db).get_status())); + idump((capitals_win_market.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}}); + 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; generate_blocks(1); @@ -978,7 +1098,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)); @@ -993,17 +1113,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); @@ -1011,19 +1131,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)) @@ -1036,13 +1156,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() @@ -1163,28 +1283,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_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_vs_blackhawks.get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets.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_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(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(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() } @@ -1198,10 +1318,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"}}); @@ -1213,14 +1333,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_id(db).get_status() == event_status::upcoming); + BOOST_CHECK(capitals_vs_blackhawks.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_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_vs_blackhawks.get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets.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); @@ -1228,19 +1348,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_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(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(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); @@ -1336,23 +1456,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; } }; @@ -1364,10 +1484,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); @@ -1380,13 +1500,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)); @@ -1401,7 +1521,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() @@ -1414,9 +1534,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() // } @@ -1430,28 +1550,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); @@ -1640,9 +1760,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(), @@ -1652,17 +1772,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()); @@ -1718,11 +1838,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(); @@ -1734,7 +1854,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); @@ -1749,7 +1869,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() @@ -1760,6 +1880,7 @@ 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); @@ -1776,31 +1897,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); @@ -1825,12 +1946,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); @@ -1845,28 +1966,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); @@ -1887,24 +2008,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(); @@ -1931,25 +2052,27 @@ 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_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(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_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_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(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_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 @@ -1973,33 +2096,40 @@ 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_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(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_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_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(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_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_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); + 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); generate_blocks(60); // as soon as a block is generated, the betting market group will settle, and the market @@ -2037,63 +2167,65 @@ 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_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(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_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_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_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_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_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(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_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_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_vs_blackhawks.get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets.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_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_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_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_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_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_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_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(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_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 @@ -2123,63 +2255,65 @@ 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_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(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_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_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_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_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_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(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_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_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_vs_blackhawks.get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets.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_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_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_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_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_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_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_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(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_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 @@ -2207,53 +2341,55 @@ 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_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(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_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_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_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_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_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_vs_blackhawks.get_status() == event_status::in_progress); + BOOST_CHECK(moneyline_betting_markets.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_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_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_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_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_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_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_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(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_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 @@ -2278,78 +2414,80 @@ 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_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_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); // 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_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); + 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); // 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_id(db).get_status() == event_status::in_progress); - BOOST_REQUIRE(moneyline_betting_markets_id(db).get_status() == betting_market_group_status::in_play); + BOOST_REQUIRE(capitals_vs_blackhawks.get_status() == event_status::in_progress); + BOOST_REQUIRE(moneyline_betting_markets.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_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); + 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); // 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_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_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); // 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}); @@ -2379,25 +2517,27 @@ 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_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_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_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_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_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_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 @@ -2429,45 +2569,47 @@ 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_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(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_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_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_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_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_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_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_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_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(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_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 @@ -2486,97 +2628,99 @@ 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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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 @@ -2625,47 +2769,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(); @@ -2693,31 +2837,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; @@ -2726,11 +2870,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; @@ -2754,17 +2898,21 @@ 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); - update_event(cilic_vs_federer_id, _name = internationalized_string_type({{"en", "R. Federer vs. M. Cilic"}})); + 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"}})); generate_blocks(13); diff --git a/tests/cli/son.cpp b/tests/cli/son.cpp index 1996c267..cf4fd8ed 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -39,7 +39,7 @@ public: fixture_(fixture) { fixture_.init_nathan(); - fixture_.generate_blocks(HARDFORK_SON_FOR_HIVE_TIME); + fixture_.generate_blocks(HARDFORK_SON_TIME); fixture_.generate_block(); } @@ -121,12 +121,10 @@ BOOST_AUTO_TEST_CASE( create_sons ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; - sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; - sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); auto son1_obj = con.wallet_api_ptr->get_son("son1account"); @@ -155,7 +153,6 @@ BOOST_AUTO_TEST_CASE( cli_update_son ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; - sidechain_public_keys[sidechain_type::hive] = "hive account 1"; son_test_helper sth(*this); sth.create_son("sonmember", "http://sonmember", sidechain_public_keys); @@ -170,7 +167,6 @@ BOOST_AUTO_TEST_CASE( cli_update_son ) // update SON sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; - sidechain_public_keys[sidechain_type::hive] = "hive account 2"; con.wallet_api_ptr->update_son("sonmember", "http://sonmember_updated", "", sidechain_public_keys, true); son_data = con.wallet_api_ptr->get_son("sonmember"); @@ -201,12 +197,10 @@ BOOST_AUTO_TEST_CASE( son_voting ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; - sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; - sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); BOOST_TEST_MESSAGE("Voting for SONs"); @@ -298,7 +292,6 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture ) { sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); - sidechain_public_keys[sidechain_type::hive] = "hive account " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, @@ -373,12 +366,10 @@ BOOST_AUTO_TEST_CASE( list_son ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; - sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; - sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); auto res = con.wallet_api_ptr->list_sons("", 100); @@ -405,12 +396,10 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; - sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; - sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); BOOST_TEST_MESSAGE("Vote for 2 accounts with update_son_votes"); @@ -566,12 +555,10 @@ BOOST_AUTO_TEST_CASE( related_functions ) sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; - sidechain_public_keys[sidechain_type::hive] = "hive account 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; - sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); gpo = con.wallet_api_ptr->get_global_properties(); @@ -605,7 +592,6 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture ) { sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); - sidechain_public_keys[sidechain_type::hive] = "hive account " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, @@ -673,7 +659,6 @@ BOOST_AUTO_TEST_CASE( maintenance_test ) { sidechain_public_keys.clear(); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); - sidechain_public_keys[sidechain_type::hive] = "hive account " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, diff --git a/tests/common/betting_test_markets.hpp b/tests/common/betting_test_markets.hpp index e774267b..f67dc067 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_id_type ice_hockey_id = (*db.get_index_type().indices().get().rbegin()).id; \ - create_event_group({{"en", "NHL"}, {"zh_Hans", "國家冰球聯盟"}, {"ja", "ナショナルホッケーリーグ"}}, ice_hockey_id); \ + 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_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); \ + 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_id_type capitals_vs_blackhawks_id = (*db.get_index_type().indices().get().rbegin()).id; \ + 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_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); \ + 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_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"}}); \ + 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_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"}}); \ + 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_id_type& blackhawks_win_market_id = (*db.get_index_type().indices().get().rbegin()).id; \ - (void)capitals_win_market_id; (void)blackhawks_win_market_id; + 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); \ + 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_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"}}); \ + 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_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"}}); \ + 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_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; \ + 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); \ + 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_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"}}); \ + 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_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"}}); \ + 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_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; \ + 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); \ + 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_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"}}); \ + 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_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"}}); \ + 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_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; + 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_id_type tennis_rules_id = (*db.get_index_type().indices().get().rbegin()).id; \ + const betting_market_rules_object& tennis_rules = *db.get_index_type().indices().get().rbegin(); \ create_sport({{"en", "Tennis"}}); \ generate_blocks(1); \ - const sport_id_type tennis_id = (*db.get_index_type().indices().get().rbegin()).id; \ - create_event_group({{"en", "Wimbledon"}}, tennis_id); \ + const sport_object& tennis = *db.get_index_type().indices().get().rbegin(); \ + create_event_group({{"en", "Wimbledon"}}, tennis.id); \ generate_blocks(1); \ - 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); \ + 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_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); \ + 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_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); \ + 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_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); \ + 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_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"}}); \ + 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_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"}}); \ + 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_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"}}); \ + 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_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"}});\ + 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_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); \ + 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_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); \ + 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_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"}}); \ + 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_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"}}); \ + 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_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; + 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; // 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,18 +155,19 @@ 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; + 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; // 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 a88f0804..42fd6137 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include @@ -204,28 +203,20 @@ 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 ); - } - - 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" ); +{ 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() } fc::ecc::private_key database_fixture::generate_private_key(string seed) { @@ -336,14 +327,6 @@ 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 cd6ac185..366e707e 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -127,9 +127,7 @@ 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(); \ - (void) name ## _private_key; \ - (void) name ## _public_key; + public_key_type name ## _public_key = name ## _private_key.get_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 5a585070..af53ee91 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_egenesis_none ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE graphene_app graphene_chain graphene_egenesis_none fc ${CMAKE_DL_LIBS} ${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 c749d790..20fe878c 100644 --- a/tests/peerplays_sidechain/bitcoin_transaction_tests.cpp +++ b/tests/peerplays_sidechain/bitcoin_transaction_tests.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/tests/tests/affiliate_tests.cpp b/tests/tests/affiliate_tests.cpp index c55c4440..804d9e8a 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_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); + 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); generate_blocks(1); - 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"}}); + 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"}}); generate_blocks(1); - 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"}}); + 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"}}); generate_blocks(1); - const betting_market_id_type blackhawks_win_market2_id = (*db.get_index_type().indices().get().rbegin()).id; + const betting_market_object& blackhawks_win_market2 = *db.get_index_type().indices().get().rbegin(); // 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 7571feb6..9885b548 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( uint64_t i = 0; i < genesis_state.initial_active_witnesses; ++i ) + for( int 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 792a300e..a6a19f06 100644 --- a/tests/tests/confidential_tests.cpp +++ b/tests/tests/confidential_tests.cpp @@ -64,6 +64,7 @@ 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 e0644b1b..9585d4a1 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(); - db.create( [&]( account_balance_object& obj ){ + const auto& bal_obj1 = 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 facf77fb..a3869b36 100644 --- a/tests/tests/dividend_tests.cpp +++ b/tests/tests/dividend_tests.cpp @@ -219,6 +219,8 @@ 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) @@ -377,6 +379,7 @@ 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) @@ -510,6 +513,28 @@ 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; @@ -522,6 +547,8 @@ 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) @@ -543,6 +570,16 @@ 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 f716281e..14be6fe2 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,6 +546,7 @@ 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); @@ -573,7 +574,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); @@ -670,18 +671,10 @@ 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); @@ -691,10 +684,6 @@ 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); @@ -702,29 +691,10 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 100); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - // 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); + advance_x_maint(4); //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 @@ -733,36 +703,10 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 83); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - - // 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); - + + advance_x_maint(10); //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); @@ -770,28 +714,8 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 66); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - // 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); - + advance_x_maint(10); + // 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); @@ -801,28 +725,8 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 50); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - // 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); - + advance_x_maint(10); + // 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); @@ -833,28 +737,8 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 33); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - // 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); - + advance_x_maint(10); + // 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); @@ -864,31 +748,14 @@ 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(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); - + advance_x_maint(5); // 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, @@ -896,16 +763,14 @@ 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); - - // 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); + generate_block(); // go to maint generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); @@ -916,17 +781,7 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(witness1.total_votes, 100); BOOST_CHECK_EQUAL(witness2.total_votes, 100); - 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); + advance_x_maint(10); witness1 = witness_id_type(1)(db); witness2 = witness_id_type(2)(db); @@ -937,21 +792,7 @@ BOOST_AUTO_TEST_CASE( voting ) vote_for(bob_id, witness2.vote_id, bob_private_key); generate_block(); - // 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); + advance_x_maint(10); witness1 = witness_id_type(1)(db); witness2 = witness_id_type(2)(db); @@ -961,11 +802,6 @@ 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); @@ -992,7 +828,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) ) @@ -1001,9 +837,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())); @@ -1231,7 +1067,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); @@ -1244,12 +1080,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"); @@ -1467,13 +1303,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(); @@ -1481,7 +1317,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 8c975649..f3b46fe7 100644 --- a/tests/tests/history_api_tests.cpp +++ b/tests/tests/history_api_tests.cpp @@ -415,8 +415,6 @@ 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()); @@ -425,8 +423,6 @@ 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); @@ -496,8 +492,6 @@ 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()); @@ -509,8 +503,6 @@ 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 c96abc09..063c15c1 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,8 +128,7 @@ BOOST_AUTO_TEST_CASE( tickets_purchase_test ) trx.operations.clear(); BOOST_CHECK( tpo.amount == db.get_balance( test_asset.get_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 ) ); + BOOST_CHECK( tpo.tickets_to_buy == 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 deleted file mode 100644 index 02d8bdc1..00000000 --- a/tests/tests/nft_lottery_tests.cpp +++ /dev/null @@ -1,842 +0,0 @@ -/* - * 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 6caec826..3093f0b0 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -1561,6 +1561,7 @@ 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/son_operations_tests.cpp b/tests/tests/son_operations_tests.cpp index 1e3bb7e4..5fee05d5 100644 --- a/tests/tests/son_operations_tests.cpp +++ b/tests/tests/son_operations_tests.cpp @@ -491,32 +491,12 @@ BOOST_AUTO_TEST_CASE( son_pay_test ) // Modify the transaction signed statistics of Alice's SON db.modify( *son_stats_obj1, [&]( son_statistics_object& _s) { - _s.txs_signed[sidechain_type::bitcoin] = 2; - _s.txs_signed[sidechain_type::hive] = 4; - - _s.total_txs_signed[sidechain_type::bitcoin] = 2; - _s.total_txs_signed[sidechain_type::hive] = 4; - - _s.sidechain_txs_reported[sidechain_type::bitcoin] = 4; - _s.sidechain_txs_reported[sidechain_type::hive] = 8; - - _s.total_sidechain_txs_reported[sidechain_type::bitcoin] = 4; - _s.total_sidechain_txs_reported[sidechain_type::hive] = 8; + _s.txs_signed = 2; }); // Modify the transaction signed statistics of Bob's SON db.modify( *son_stats_obj2, [&]( son_statistics_object& _s) { - _s.txs_signed[sidechain_type::bitcoin] = 3; - _s.txs_signed[sidechain_type::hive] = 6; - - _s.total_txs_signed[sidechain_type::bitcoin] = 3; - _s.total_txs_signed[sidechain_type::hive] = 6; - - _s.sidechain_txs_reported[sidechain_type::bitcoin] = 6; - _s.sidechain_txs_reported[sidechain_type::hive] = 12; - - _s.total_sidechain_txs_reported[sidechain_type::bitcoin] = 6; - _s.total_sidechain_txs_reported[sidechain_type::hive] = 12; + _s.txs_signed = 3; }); // Note the balances before the maintenance @@ -526,23 +506,11 @@ BOOST_AUTO_TEST_CASE( son_pay_test ) generate_blocks(dpo.next_maintenance_time); generate_block(); // Check if the signed transaction statistics are reset for both SONs - BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed.at(sidechain_type::bitcoin), 0); - BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed.at(sidechain_type::hive), 0); - BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed.at(sidechain_type::bitcoin), 0); - BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed.at(sidechain_type::hive), 0); - BOOST_REQUIRE_EQUAL(son_stats_obj1->sidechain_txs_reported.at(sidechain_type::bitcoin), 0); - BOOST_REQUIRE_EQUAL(son_stats_obj1->sidechain_txs_reported.at(sidechain_type::hive), 0); - BOOST_REQUIRE_EQUAL(son_stats_obj2->sidechain_txs_reported.at(sidechain_type::bitcoin), 0); - BOOST_REQUIRE_EQUAL(son_stats_obj2->sidechain_txs_reported.at(sidechain_type::hive), 0); + BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed, 0); + BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed, 0); - BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed.at(sidechain_type::bitcoin), 2); - BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed.at(sidechain_type::hive), 4); - BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed.at(sidechain_type::bitcoin), 3); - BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed.at(sidechain_type::hive), 6); - BOOST_REQUIRE_EQUAL(son_stats_obj1->total_sidechain_txs_reported.at(sidechain_type::bitcoin), 4); - BOOST_REQUIRE_EQUAL(son_stats_obj1->total_sidechain_txs_reported.at(sidechain_type::hive), 8); - BOOST_REQUIRE_EQUAL(son_stats_obj2->total_sidechain_txs_reported.at(sidechain_type::bitcoin), 6); - BOOST_REQUIRE_EQUAL(son_stats_obj2->total_sidechain_txs_reported.at(sidechain_type::hive), 12); + BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed, 2); + BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed, 3); // Check that Alice and Bob are paid for signing the transactions in the previous day/cycle BOOST_REQUIRE_EQUAL(db.get_balance(obj1->son_account, asset_id_type()).amount.value, 80+obj1_balance); BOOST_REQUIRE_EQUAL(db.get_balance(obj2->son_account, asset_id_type()).amount.value, 120+obj2_balance); diff --git a/tests/tests/voting_tests.cpp b/tests/tests/voting_tests.cpp index a6f41675..79f80e1f 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 - db.head_block_time().sec_since_epoch(); + auto round2 = 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 0593fd79..8aa88479 100644 --- a/tests/tournament/tournament_tests.cpp +++ b/tests/tournament/tournament_tests.cpp @@ -1731,8 +1731,7 @@ 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; @@ -1944,8 +1943,7 @@ 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;