This adds the most important updates to Graphene from BitShares. Most notably, https://github.com/bitshares/bitshares-core/issues/1506 Second most notably, it updates Peerplays' FC to be in sync with BitShares FC. This is a squash commit of several subcommits. The subcommit messages are reproduced below: Replace fc::uint128 with boost::multiprecision::uint128_t replace smart_ref with shared_ptr Fixes/Remove Unused Remove NTP time Remove old macro This macro is now in FC, so no need to define it here anymore Replaced fc::array with std::array Separate exception declaration and implementation Adapted to fc promise changes Fixes Add back in some of Peter's fixes that got lost in the cherry pick _hash endianness fixes Remove all uses of fc/smart_ref It's gone, can't use it anymore Replace improper static_variant operator overloads with comparators Fixes Remove boost::signals from build system; it's header-only so it's not listed in cmake anymore. Also remove some unused hashing code Impl. pack/unpack functions for extension class Ref #1506: Isolate chain/protocol to its own library Ref #1506: Add object_downcast_t Allows the more concise expression `object_downcast_t<xyz>` instead of the old `typename object_downcast<xyz>::type` Ref #1506: Move ID types from db to protocol The ID types, object_id and object_id_type, were defined in the db library, and the protocol library depends on db to get these types. Technically, the ID types are defined by the protocol and used by the database, and not vice versa. Therefore these types should be in the protocol library, and db should depend on protocol to get them. This commit makes it so. Ref #1506: Isolate chain/protocol to its own library Remove commented-out index code Wrap overlength line Remove unused key types Probably fix Docker build Fix build after rebase Ref #1506/#1737: Some requested changes Ref #1506/#1737: Macro-fy ID type definitions Define macros to fully de-boilerplate ID type definitions. Externalities: - Rename transaction_object -> transaction_history_object - Rename impl_asset_dynamic_data_type -> impl_asset_dynamic_data_object_type - Rename impl_asset_bitasset_data_type -> impl_asset_bitasset_data_object_type The first is to avoid a naming collision on transaction_id_type, and the other two are to maintain consistency with the naming of the other types. Ref #1506/#1737: Fix clean_name() Ref #1506/#1737: Oops Fix .gitignore Externalized serialization in protocol library Fix compile sets Delete a couple of ghost files that were in the tree but not part of the project (I accidentally added them to CMakeLists while merging, but they're broken and not part of the Peerplays code), and add several files that got dropped from the build during merge. General fixes Fix warnings, build issues, unused code, etc. Fix #1772 by decprecating cli_wallet -H More fixes Fix errors and warnings and generally coax it to build Fix test I'm pretty sure this didn't break from what I did... But I can't build the original code, so I can't tell. Anyways, this one now passes... Others still fail... Small fix Fix crash in auth checks Final fixes Last round of fixes following the rebase to Beatrice Rename project in CMakeLists.txt The CMakeLists.txt declared this project as BitShares and not Peerplays, which makes it confusing in IDEs. Rename it to be clear which project is open. Resolve #374 Replace all object refs in macros with IDs, and fix affected tests to look up objects by ID rather than using invalidated refs. A full audit of all tests should be performed to eliminate any further usage of invalidated object references. Resolve #373: Add object notifiers Various fixes Fixes to various issues, primarily reflections, that cropped up during merge conflict resolution Fix startup bug in Bookie plugin Bookie plugin was preventing the node from starting up because it registered its secondary indexes to create objects in its own primary indexes to track objects being created in other primary indexes, and did so during its `initialize()` step, which is to say, before the database was loaded from disk at startup. This caused the secondary indexes to create tracker objects when the observed indexes were loading objects from disk. This then caused a failure when these tracker indexes were later loaded from disk, and the first object IDs collided. This is fixed by refraining from defining secondary indexes until the `startup()` stage rather than the `initialize()` stage. Primary indexes are registered in `initialize()`, secondary indexes are registered in `startup()`. This also involved adding a new method, "add_secondary_index()", to `object_database`, as before there was no way to do this because you couldn't get a non-const index from a non-const database. I have no idea how this was working before I got here... Fix egenesis install Fixes after updates Rebase on updated develop branch and fix conflicts
173 lines
12 KiB
C++
173 lines
12 KiB
C++
/*
|
|
* 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 "database_fixture.hpp"
|
|
|
|
#include <graphene/chain/sport_object.hpp>
|
|
#include <graphene/chain/event_object.hpp>
|
|
#include <graphene/chain/event_group_object.hpp>
|
|
#include <graphene/chain/betting_market_object.hpp>
|
|
|
|
using namespace graphene::chain;
|
|
|
|
template<class O> object_id<O::space_id, O::type_id> to_id(const O& o) { return o.id; }
|
|
|
|
#define CREATE_ICE_HOCKEY_BETTING_MARKET(never_in_play, delay_before_settling) \
|
|
create_sport({{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); \
|
|
generate_blocks(1); \
|
|
const auto ice_hockey_id = to_id(*db.get_index_type<sport_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_event_group({{"en", "NHL"}, {"zh_Hans", "國家冰球聯盟"}, {"ja", "ナショナルホッケーリーグ"}}, ice_hockey_id); \
|
|
generate_blocks(1); \
|
|
const auto nhl_id = to_id(*db.get_index_type<event_group_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_event({{"en", "Washington Capitals/Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑鷹"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホークス"}}, {{"en", "2016-17"}}, nhl_id); \
|
|
generate_blocks(1); \
|
|
const auto capitals_vs_blackhawks_id = to_id(*db.get_index_type<event_object_index>().indices().get<by_id>().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 auto betting_market_rules_id = to_id(*db.get_index_type<betting_market_rules_object_index>().indices().get<by_id>().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 auto moneyline_betting_markets_id = to_id(*db.get_index_type<betting_market_group_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(moneyline_betting_markets_id, {{"en", "Washington Capitals win"}}); \
|
|
generate_blocks(1); \
|
|
const auto capitals_win_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(moneyline_betting_markets_id, {{"en", "Chicago Blackhawks win"}}); \
|
|
generate_blocks(1); \
|
|
const auto blackhawks_win_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
(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); \
|
|
generate_blocks(1); \
|
|
const auto first_period_result_betting_markets_id = to_id(*db.get_index_type<betting_market_group_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(first_period_result_betting_markets_id, {{"en", "Washington Capitals win"}}); \
|
|
generate_blocks(1); \
|
|
const auto first_period_capitals_win_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(first_period_result_betting_markets_id, {{"en", "Chicago Blackhawks win"}}); \
|
|
generate_blocks(1); \
|
|
const auto first_period_blackhawks_win_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
(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); \
|
|
generate_blocks(1); \
|
|
const auto second_period_result_betting_markets_id = to_id(*db.get_index_type<betting_market_group_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(second_period_result_betting_markets_id, {{"en", "Washington Capitals win"}}); \
|
|
generate_blocks(1); \
|
|
const auto second_period_capitals_win_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(second_period_result_betting_markets_id, {{"en", "Chicago Blackhawks win"}}); \
|
|
generate_blocks(1); \
|
|
const auto second_period_blackhawks_win_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
(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); \
|
|
generate_blocks(1); \
|
|
const auto third_period_result_betting_markets_id = to_id(*db.get_index_type<betting_market_group_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(third_period_result_betting_markets_id, {{"en", "Washington Capitals win"}}); \
|
|
generate_blocks(1); \
|
|
const auto third_period_capitals_win_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(third_period_result_betting_markets_id, {{"en", "Chicago Blackhawks win"}}); \
|
|
generate_blocks(1); \
|
|
const auto third_period_blackhawks_win_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
(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 auto tennis_rules_id = to_id(*db.get_index_type<betting_market_rules_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_sport({{"en", "Tennis"}}); \
|
|
generate_blocks(1); \
|
|
const auto tennis_id = to_id(*db.get_index_type<sport_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_event_group({{"en", "Wimbledon"}}, tennis_id); \
|
|
generate_blocks(1); \
|
|
const auto wimbledon_id = to_id(*db.get_index_type<event_group_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_event({{"en", "R. Federer/T. Berdych"}}, {{"en", "2017"}}, wimbledon_id); \
|
|
generate_blocks(1); \
|
|
const auto berdych_vs_federer_id = to_id(*db.get_index_type<event_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_event({{"en", "M. Cilic/S. Querrye"}}, {{"en", "2017"}}, wimbledon_id); \
|
|
generate_blocks(1); \
|
|
const auto cilic_vs_querrey_id = to_id(*db.get_index_type<event_object_index>().indices().get<by_id>().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 auto moneyline_berdych_vs_federer_id = to_id(*db.get_index_type<betting_market_group_object_index>().indices().get<by_id>().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 auto moneyline_cilic_vs_querrey_id = to_id(*db.get_index_type<betting_market_group_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(moneyline_berdych_vs_federer_id, {{"en", "T. Berdych defeats R. Federer"}}); \
|
|
generate_blocks(1); \
|
|
const auto berdych_wins_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(moneyline_berdych_vs_federer_id, {{"en", "R. Federer defeats T. Berdych"}}); \
|
|
generate_blocks(1); \
|
|
const auto federer_wins_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(moneyline_cilic_vs_querrey_id, {{"en", "M. Cilic defeats S. Querrey"}}); \
|
|
generate_blocks(1); \
|
|
const auto cilic_wins_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(moneyline_cilic_vs_querrey_id, {{"en", "S. Querrey defeats M. Cilic"}});\
|
|
generate_blocks(1); \
|
|
const auto querrey_wins_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_event({{"en", "R. Federer/M. Cilic"}}, {{"en", "2017"}}, wimbledon_id); \
|
|
generate_blocks(1); \
|
|
const auto cilic_vs_federer_id = to_id(*db.get_index_type<event_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market_group({{"en", "Moneyline final"}}, cilic_vs_federer_id, tennis_rules_id, asset_id_type(), false, 0); \
|
|
generate_blocks(1); \
|
|
const auto moneyline_cilic_vs_federer_id = to_id(*db.get_index_type<betting_market_group_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(moneyline_cilic_vs_federer_id, {{"en", "R. Federer defeats M. Cilic"}}); \
|
|
generate_blocks(1); \
|
|
const auto federer_wins_final_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
create_betting_market(moneyline_cilic_vs_federer_id, {{"en", "M. Cilic defeats R. Federer"}}); \
|
|
generate_blocks(1); \
|
|
const auto cilic_wins_final_market_id = to_id(*db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin()); \
|
|
(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
|
|
struct simple_bet_test_fixture : database_fixture {
|
|
betting_market_id_type capitals_win_betting_market_id;
|
|
betting_market_id_type blackhawks_win_betting_market_id;
|
|
betting_market_group_id_type moneyline_betting_markets_id;
|
|
|
|
simple_bet_test_fixture()
|
|
{
|
|
ACTORS( (alice)(bob) );
|
|
CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0);
|
|
capitals_win_betting_market_id = capitals_win_market_id;
|
|
blackhawks_win_betting_market_id = blackhawks_win_market_id;
|
|
|
|
// give alice and bob 10k each
|
|
transfer(account_id_type(), alice_id, asset(10000));
|
|
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);
|
|
|
|
// 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);
|
|
|
|
// 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);
|
|
generate_blocks(1);
|
|
}
|
|
};
|