From 2470af6eb9c8e0801ffcd250ae0b95eab1683203 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Wed, 15 Mar 2017 17:04:27 -0400 Subject: [PATCH] Initial work on creating blockchain objects for sports betting --- libraries/app/impacted.cpp | 7 ++ libraries/chain/CMakeLists.txt | 11 +++ libraries/chain/betting_market_evaluator.cpp | 69 +++++++++++++ libraries/chain/competitor_evaluator.cpp | 51 ++++++++++ libraries/chain/db_init.cpp | 42 ++++++++ libraries/chain/event_evaluator.cpp | 50 ++++++++++ libraries/chain/event_group_evaluator.cpp | 51 ++++++++++ .../chain/betting_market_evaluator.hpp | 50 ++++++++++ .../graphene/chain/betting_market_object.hpp | 73 ++++++++++++++ .../graphene/chain/competitor_evaluator.hpp | 41 ++++++++ .../graphene/chain/competitor_object.hpp | 52 ++++++++++ .../graphene/chain/event_evaluator.hpp | 41 ++++++++ .../graphene/chain/event_group_evaluator.hpp | 41 ++++++++ .../graphene/chain/event_group_object.hpp | 52 ++++++++++ .../include/graphene/chain/event_object.hpp | 69 +++++++++++++ .../chain/protocol/betting_market.hpp | 98 +++++++++++++++++++ .../graphene/chain/protocol/competitor.hpp | 56 +++++++++++ .../include/graphene/chain/protocol/event.hpp | 59 +++++++++++ .../graphene/chain/protocol/event_group.hpp | 53 ++++++++++ .../graphene/chain/protocol/operations.hpp | 13 ++- .../include/graphene/chain/protocol/sport.hpp | 51 ++++++++++ .../include/graphene/chain/protocol/types.hpp | 32 ++++++ .../graphene/chain/sport_evaluator.hpp | 41 ++++++++ .../include/graphene/chain/sport_object.hpp | 51 ++++++++++ libraries/chain/protocol/betting_market.cpp | 40 ++++++++ libraries/chain/protocol/competitor.cpp | 35 +++++++ libraries/chain/protocol/event.cpp | 35 +++++++ libraries/chain/protocol/event_group.cpp | 35 +++++++ libraries/chain/protocol/sport.cpp | 35 +++++++ libraries/chain/sport_evaluator.cpp | 50 ++++++++++ programs/js_operation_serializer/main.cpp | 5 + tests/tests/operation_tests2.cpp | 71 ++++++++++++++ 32 files changed, 1459 insertions(+), 1 deletion(-) create mode 100644 libraries/chain/betting_market_evaluator.cpp create mode 100644 libraries/chain/competitor_evaluator.cpp create mode 100644 libraries/chain/event_evaluator.cpp create mode 100644 libraries/chain/event_group_evaluator.cpp create mode 100644 libraries/chain/include/graphene/chain/betting_market_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/betting_market_object.hpp create mode 100644 libraries/chain/include/graphene/chain/competitor_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/competitor_object.hpp create mode 100644 libraries/chain/include/graphene/chain/event_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/event_group_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/event_group_object.hpp create mode 100644 libraries/chain/include/graphene/chain/event_object.hpp create mode 100644 libraries/chain/include/graphene/chain/protocol/betting_market.hpp create mode 100644 libraries/chain/include/graphene/chain/protocol/competitor.hpp create mode 100644 libraries/chain/include/graphene/chain/protocol/event.hpp create mode 100644 libraries/chain/include/graphene/chain/protocol/event_group.hpp create mode 100644 libraries/chain/include/graphene/chain/protocol/sport.hpp create mode 100644 libraries/chain/include/graphene/chain/sport_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/sport_object.hpp create mode 100644 libraries/chain/protocol/betting_market.cpp create mode 100644 libraries/chain/protocol/competitor.cpp create mode 100644 libraries/chain/protocol/event.cpp create mode 100644 libraries/chain/protocol/event_group.cpp create mode 100644 libraries/chain/protocol/sport.cpp create mode 100644 libraries/chain/sport_evaluator.cpp diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index 85787423..c5b2628d 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -203,6 +203,13 @@ struct get_impacted_account_visitor _impacted.insert( op.account_id ); } + void operator()( const sport_create_operation& op ) {} + void operator()( const competitor_create_operation& op ) {} + void operator()( const event_group_create_operation& op ) {} + void operator()( const event_create_operation& op ) {} + void operator()( const betting_market_group_create_operation& op ) {} + void operator()( const betting_market_create_operation& op ) {} + }; void operation_get_impacted_accounts( const operation& op, flat_set& result ) diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 9cc4285d..602c26df 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -89,6 +89,17 @@ add_library( graphene_chain is_authorized_asset.cpp + protocol/sport.cpp + sport_evaluator.cpp + protocol/competitor.cpp + competitor_evaluator.cpp + protocol/event_group.cpp + event_group_evaluator.cpp + protocol/event.cpp + event_evaluator.cpp + protocol/betting_market.cpp + betting_market_evaluator.cpp + ${HEADERS} "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" ) diff --git a/libraries/chain/betting_market_evaluator.cpp b/libraries/chain/betting_market_evaluator.cpp new file mode 100644 index 00000000..77a15711 --- /dev/null +++ b/libraries/chain/betting_market_evaluator.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include + +namespace graphene { namespace chain { + +void_result betting_market_group_create_evaluator::do_evaluate(const betting_market_group_create_operation& op) +{ try { + FC_ASSERT(trx_state->_is_proposed_trx); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type betting_market_group_create_evaluator::do_apply(const betting_market_group_create_operation& op) +{ try { + const betting_market_group_object& new_betting_market_group = + db().create( [&]( betting_market_group_object& betting_market_group_obj ) { + betting_market_group_obj.event_id = op.event_id; + betting_market_group_obj.options = op.options; + }); + return new_betting_market_group.id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +void_result betting_market_create_evaluator::do_evaluate(const betting_market_create_operation& op) +{ try { + FC_ASSERT(trx_state->_is_proposed_trx); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type betting_market_create_evaluator::do_apply(const betting_market_create_operation& op) +{ try { + const betting_market_object& new_betting_market = + db().create( [&]( betting_market_object& betting_market_obj ) { + betting_market_obj.group_id = op.group_id; + betting_market_obj.payout_condition = op.payout_condition; + betting_market_obj.asset_id = op.asset_id; + }); + return new_betting_market.id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // graphene::chain diff --git a/libraries/chain/competitor_evaluator.cpp b/libraries/chain/competitor_evaluator.cpp new file mode 100644 index 00000000..3d67708d --- /dev/null +++ b/libraries/chain/competitor_evaluator.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include + +namespace graphene { namespace chain { + +void_result competitor_create_evaluator::do_evaluate(const competitor_create_operation& op) +{ try { + FC_ASSERT(trx_state->_is_proposed_trx); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type competitor_create_evaluator::do_apply(const competitor_create_operation& op) +{ try { + const competitor_object& new_competitor = + db().create( [&]( competitor_object& competitor_obj ) { + competitor_obj.name = op.name; + competitor_obj.sport_id = op.sport_id; + }); + return new_competitor.id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // graphene::chain diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index ffe52715..ec4c2d60 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -47,6 +47,13 @@ #include #include + +#include +#include +#include +#include +#include + #include #include #include @@ -61,6 +68,11 @@ #include #include #include +#include +#include +#include +#include +#include #include @@ -126,6 +138,24 @@ const uint8_t witness_object::type_id; const uint8_t worker_object::space_id; const uint8_t worker_object::type_id; +const uint8_t sport_object::space_id; +const uint8_t sport_object::type_id; + +const uint8_t competitor_object::space_id; +const uint8_t competitor_object::type_id; + +const uint8_t event_group_object::space_id; +const uint8_t event_group_object::type_id; + +const uint8_t event_object::space_id; +const uint8_t event_object::type_id; + +const uint8_t betting_market_group_object::space_id; +const uint8_t betting_market_group_object::type_id; + +const uint8_t betting_market_object::space_id; +const uint8_t betting_market_object::type_id; + void database::initialize_evaluators() { @@ -171,6 +201,12 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); + register_evaluator(); + register_evaluator(); + register_evaluator(); + register_evaluator(); + register_evaluator(); + register_evaluator(); } void database::initialize_indexes() @@ -199,6 +235,12 @@ 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 >(); + add_index< primary_index >(); + add_index< primary_index >(); + add_index< primary_index >(); //Implementation object indexes add_index< primary_index >(); diff --git a/libraries/chain/event_evaluator.cpp b/libraries/chain/event_evaluator.cpp new file mode 100644 index 00000000..d0d903ce --- /dev/null +++ b/libraries/chain/event_evaluator.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include + +namespace graphene { namespace chain { + +void_result event_create_evaluator::do_evaluate(const event_create_operation& op) +{ try { + FC_ASSERT(trx_state->_is_proposed_trx); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type event_create_evaluator::do_apply(const event_create_operation& op) +{ try { + const event_object& new_event = + db().create( [&]( event_object& event_obj ) { + event_obj.name = op.name; + }); + return new_event.id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // graphene::chain diff --git a/libraries/chain/event_group_evaluator.cpp b/libraries/chain/event_group_evaluator.cpp new file mode 100644 index 00000000..f676e334 --- /dev/null +++ b/libraries/chain/event_group_evaluator.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include + +namespace graphene { namespace chain { + +void_result event_group_create_evaluator::do_evaluate(const event_group_create_operation& op) +{ try { + FC_ASSERT(trx_state->_is_proposed_trx); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type event_group_create_evaluator::do_apply(const event_group_create_operation& op) +{ try { + const event_group_object& new_event_group = + db().create( [&]( event_group_object& event_group_obj ) { + event_group_obj.name = op.name; + event_group_obj.sport_id = op.sport_id; + }); + return new_event_group.id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp b/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp new file mode 100644 index 00000000..41a38619 --- /dev/null +++ b/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + + class betting_market_group_create_evaluator : public evaluator + { + public: + typedef betting_market_group_create_operation operation_type; + + void_result do_evaluate( const betting_market_group_create_operation& o ); + object_id_type do_apply( const betting_market_group_create_operation& o ); + }; + + class betting_market_create_evaluator : public evaluator + { + public: + typedef betting_market_create_operation operation_type; + + void_result do_evaluate( const betting_market_create_operation& o ); + object_id_type do_apply( const betting_market_create_operation& o ); + }; + +} } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/betting_market_object.hpp b/libraries/chain/include/graphene/chain/betting_market_object.hpp new file mode 100644 index 00000000..c8953e9a --- /dev/null +++ b/libraries/chain/include/graphene/chain/betting_market_object.hpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + +class database; + +class betting_market_group_object : public graphene::db::abstract_object< betting_market_group_object > +{ + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = betting_market_group_object_type; + + event_id_type event_id; + + betting_market_options_type options; +}; + +class betting_market_object : public graphene::db::abstract_object< betting_market_object > +{ + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = betting_market_object_type; + + betting_market_group_id_type group_id; + + internationalized_string_type payout_condition; + + asset_id_type asset_id; +}; + +typedef multi_index_container< + betting_market_group_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > > > > betting_market_group_object_multi_index_type; +typedef generic_index betting_market_group_object_index; + +typedef multi_index_container< + betting_market_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > > > > betting_market_object_multi_index_type; + +typedef generic_index betting_market_object_index; +} } // graphene::chain + +FC_REFLECT_DERIVED( graphene::chain::betting_market_group_object, (graphene::db::object), (event_id)(options) ) +FC_REFLECT_DERIVED( graphene::chain::betting_market_object, (graphene::db::object), (group_id)(payout_condition)(asset_id) ) diff --git a/libraries/chain/include/graphene/chain/competitor_evaluator.hpp b/libraries/chain/include/graphene/chain/competitor_evaluator.hpp new file mode 100644 index 00000000..a22c9f50 --- /dev/null +++ b/libraries/chain/include/graphene/chain/competitor_evaluator.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + + class competitor_create_evaluator : public evaluator + { + public: + typedef competitor_create_operation operation_type; + + void_result do_evaluate( const competitor_create_operation& o ); + object_id_type do_apply( const competitor_create_operation& o ); + }; + +} } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/competitor_object.hpp b/libraries/chain/include/graphene/chain/competitor_object.hpp new file mode 100644 index 00000000..8ca495f0 --- /dev/null +++ b/libraries/chain/include/graphene/chain/competitor_object.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + +class database; + +class competitor_object : public graphene::db::abstract_object< competitor_object > +{ + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = competitor_object_type; + + internationalized_string_type name; + sport_id_type sport_id; +}; + +typedef multi_index_container< + competitor_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > > > > competitor_object_multi_index_type; + +typedef generic_index competitor_object_index; +} } // graphene::chain + +FC_REFLECT_DERIVED( graphene::chain::competitor_object, (graphene::db::object), (name)(sport_id) ) diff --git a/libraries/chain/include/graphene/chain/event_evaluator.hpp b/libraries/chain/include/graphene/chain/event_evaluator.hpp new file mode 100644 index 00000000..d271fa72 --- /dev/null +++ b/libraries/chain/include/graphene/chain/event_evaluator.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + + class event_create_evaluator : public evaluator + { + public: + typedef event_create_operation operation_type; + + void_result do_evaluate( const event_create_operation& o ); + object_id_type do_apply( const event_create_operation& o ); + }; + +} } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/event_group_evaluator.hpp b/libraries/chain/include/graphene/chain/event_group_evaluator.hpp new file mode 100644 index 00000000..e1bca6a3 --- /dev/null +++ b/libraries/chain/include/graphene/chain/event_group_evaluator.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + + class event_group_create_evaluator : public evaluator + { + public: + typedef event_group_create_operation operation_type; + + void_result do_evaluate( const event_group_create_operation& o ); + object_id_type do_apply( const event_group_create_operation& o ); + }; + +} } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/event_group_object.hpp b/libraries/chain/include/graphene/chain/event_group_object.hpp new file mode 100644 index 00000000..a5d4584d --- /dev/null +++ b/libraries/chain/include/graphene/chain/event_group_object.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + +class database; + +class event_group_object : public graphene::db::abstract_object< event_group_object > +{ + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = event_group_object_type; + + internationalized_string_type name; + sport_id_type sport_id; +}; + +typedef multi_index_container< + event_group_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > > > > event_group_object_multi_index_type; + +typedef generic_index event_group_object_index; +} } // graphene::chain + +FC_REFLECT_DERIVED( graphene::chain::event_group_object, (graphene::db::object), (name)(sport_id) ) diff --git a/libraries/chain/include/graphene/chain/event_object.hpp b/libraries/chain/include/graphene/chain/event_object.hpp new file mode 100644 index 00000000..247e3636 --- /dev/null +++ b/libraries/chain/include/graphene/chain/event_object.hpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + +class database; + +class event_object : public graphene::db::abstract_object< event_object > +{ + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = event_object_type; + + enum status + { + upcoming, + in_progress, + completed, + canceled, + STATUS_COUNT + }; + + internationalized_string_type name; + + internationalized_string_type season; + + optional start_time; + + event_group_id_type event_group_id; + + vector competitors; +}; + +typedef multi_index_container< + event_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > > > > event_object_multi_index_type; + +typedef generic_index event_object_index; +} } // graphene::chain + +FC_REFLECT_ENUM( graphene::chain::event_object::status, (upcoming)(in_progress)(completed)(canceled)(STATUS_COUNT) ) +FC_REFLECT_DERIVED( graphene::chain::event_object, (graphene::db::object), (name)(season)(start_time)(event_group_id)(competitors) ) diff --git a/libraries/chain/include/graphene/chain/protocol/betting_market.hpp b/libraries/chain/include/graphene/chain/protocol/betting_market.hpp new file mode 100644 index 00000000..f61650e5 --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/betting_market.hpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include + +namespace graphene { namespace chain { + + +enum betting_market_type { + moneyline, + spread, + over_under, + BETTING_MARKET_TYPE_COUNT +}; + +struct moneyline_market_options {}; + +struct spread_market_options { + int32_t margin; +}; + +struct over_under_market_options { + uint32_t score; +}; + +typedef static_variant betting_market_options_type; + +struct betting_market_group_create_operation : public base_operation +{ + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; + asset fee; + + event_id_type event_id; + + betting_market_options_type options; + + extensions_type extensions; + + account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + void validate()const; +}; + +struct betting_market_create_operation : public base_operation +{ + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; + asset fee; + + betting_market_group_id_type group_id; + + internationalized_string_type payout_condition; + + asset_id_type asset_id; + + extensions_type extensions; + + account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + void validate()const; +}; + +} } + +FC_REFLECT_ENUM( graphene::chain::betting_market_type, (moneyline)(spread)(over_under)(BETTING_MARKET_TYPE_COUNT) ) + +FC_REFLECT( graphene::chain::moneyline_market_options, ) +FC_REFLECT( graphene::chain::spread_market_options, (margin) ) +FC_REFLECT( graphene::chain::over_under_market_options, (score) ) +FC_REFLECT_TYPENAME( graphene::chain::betting_market_options_type ) + +FC_REFLECT( graphene::chain::betting_market_group_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::betting_market_group_create_operation, + (fee)(event_id)(options)(extensions) ) + +FC_REFLECT( graphene::chain::betting_market_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::betting_market_create_operation, + (fee)(group_id)(payout_condition)(asset_id)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/competitor.hpp b/libraries/chain/include/graphene/chain/protocol/competitor.hpp new file mode 100644 index 00000000..4406a734 --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/competitor.hpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include + +namespace graphene { namespace chain { + +struct competitor_create_operation : public base_operation +{ + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; + asset fee; + + /** + * The name of the competitor + */ + internationalized_string_type name; + + /** + * The sport the competitor, um, competes in + */ + sport_id_type sport_id; + + extensions_type extensions; + + account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + void validate()const; +}; + +} } + +FC_REFLECT( graphene::chain::competitor_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::competitor_create_operation, + (fee)(name)(sport_id)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/event.hpp b/libraries/chain/include/graphene/chain/protocol/event.hpp new file mode 100644 index 00000000..6830cf0b --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/event.hpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include + +namespace graphene { namespace chain { + +struct event_create_operation : public base_operation +{ + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; + asset fee; + + /** + * The name of the event + */ + internationalized_string_type name; + + internationalized_string_type season; + + optional start_time; + + event_group_id_type event_group_id; + + vector competitors; + + extensions_type extensions; + + account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + void validate()const; +}; + +} } + +FC_REFLECT( graphene::chain::event_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::event_create_operation, + (fee)(name)(season)(start_time)(event_group_id)(competitors)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/event_group.hpp b/libraries/chain/include/graphene/chain/protocol/event_group.hpp new file mode 100644 index 00000000..d678a671 --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/event_group.hpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include + +namespace graphene { namespace chain { + +struct event_group_create_operation : public base_operation +{ + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; + asset fee; + + /** + * The name of the event_group + */ + internationalized_string_type name; + + sport_id_type sport_id; + + extensions_type extensions; + + account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + void validate()const; +}; + +} } + +FC_REFLECT( graphene::chain::event_group_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::event_group_create_operation, + (fee)(name)(sport_id)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index 7f2639f1..4b04a44f 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -38,6 +38,11 @@ #include #include #include +#include +#include +#include +#include +#include namespace graphene { namespace chain { @@ -91,7 +96,13 @@ namespace graphene { namespace chain { transfer_from_blind_operation, asset_settle_cancel_operation, // VIRTUAL asset_claim_fees_operation, - fba_distribute_operation // VIRTUAL + fba_distribute_operation, // VIRTUAL + sport_create_operation, + competitor_create_operation, + event_group_create_operation, + event_create_operation, + betting_market_group_create_operation, + betting_market_create_operation > operation; /// @} // operations group diff --git a/libraries/chain/include/graphene/chain/protocol/sport.hpp b/libraries/chain/include/graphene/chain/protocol/sport.hpp new file mode 100644 index 00000000..2400577e --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/sport.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include + +namespace graphene { namespace chain { + +struct sport_create_operation : public base_operation +{ + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; + asset fee; + + /** + * The name of the sport + */ + internationalized_string_type name; + + extensions_type extensions; + + account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + void validate()const; +}; + +} } + +FC_REFLECT( graphene::chain::sport_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::sport_create_operation, + (fee)(name)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index d7864f90..68b2a6dc 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -134,6 +134,12 @@ namespace graphene { namespace chain { vesting_balance_object_type, worker_object_type, balance_object_type, + sport_object_type, + competitor_object_type, + event_group_object_type, + event_object_type, + betting_market_group_object_type, + betting_market_object_type, OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types }; @@ -175,6 +181,12 @@ namespace graphene { namespace chain { class worker_object; class balance_object; class blinded_balance_object; + class sport_object; + class competitor_object; + class event_group_object; + class event_object; + class betting_market_group_object; + class betting_market_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; @@ -190,6 +202,12 @@ namespace graphene { namespace chain { typedef object_id< protocol_ids, vesting_balance_object_type, vesting_balance_object> vesting_balance_id_type; typedef object_id< protocol_ids, worker_object_type, worker_object> worker_id_type; typedef object_id< protocol_ids, balance_object_type, balance_object> balance_id_type; + typedef object_id< protocol_ids, sport_object_type, sport_object> sport_id_type; + typedef object_id< protocol_ids, competitor_object_type, competitor_object> competitor_id_type; + typedef object_id< protocol_ids, event_group_object_type, event_group_object> event_group_id_type; + typedef object_id< protocol_ids, event_object_type, event_object> event_id_type; + typedef object_id< protocol_ids, betting_market_group_object_type, betting_market_group_object> betting_market_group_id_type; + typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type; // implementation types class global_property_object; @@ -304,6 +322,8 @@ namespace graphene { namespace chain { friend bool operator == ( const extended_private_key_type& p1, const extended_private_key_type& p2); friend bool operator != ( const extended_private_key_type& p1, const extended_private_key_type& p2); }; + + typedef flat_map internationalized_string_type; } } // graphene::chain namespace fc @@ -340,6 +360,12 @@ FC_REFLECT_ENUM( graphene::chain::object_type, (vesting_balance_object_type) (worker_object_type) (balance_object_type) + (sport_object_type) + (competitor_object_type) + (event_group_object_type) + (event_object_type) + (betting_market_group_object_type) + (betting_market_object_type) (OBJECT_TYPE_COUNT) ) FC_REFLECT_ENUM( graphene::chain::impl_object_type, @@ -378,6 +404,12 @@ FC_REFLECT_TYPENAME( graphene::chain::withdraw_permission_id_type ) FC_REFLECT_TYPENAME( graphene::chain::vesting_balance_id_type ) FC_REFLECT_TYPENAME( graphene::chain::worker_id_type ) FC_REFLECT_TYPENAME( graphene::chain::balance_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::sport_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::competitor_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::event_group_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::event_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::betting_market_group_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::betting_market_id_type ) FC_REFLECT_TYPENAME( graphene::chain::global_property_id_type ) FC_REFLECT_TYPENAME( graphene::chain::dynamic_global_property_id_type ) FC_REFLECT_TYPENAME( graphene::chain::asset_dynamic_data_id_type ) diff --git a/libraries/chain/include/graphene/chain/sport_evaluator.hpp b/libraries/chain/include/graphene/chain/sport_evaluator.hpp new file mode 100644 index 00000000..b75ab615 --- /dev/null +++ b/libraries/chain/include/graphene/chain/sport_evaluator.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + + class sport_create_evaluator : public evaluator + { + public: + typedef sport_create_operation operation_type; + + void_result do_evaluate( const sport_create_operation& o ); + object_id_type do_apply( const sport_create_operation& o ); + }; + +} } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/sport_object.hpp b/libraries/chain/include/graphene/chain/sport_object.hpp new file mode 100644 index 00000000..314ebf17 --- /dev/null +++ b/libraries/chain/include/graphene/chain/sport_object.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include +#include + +namespace graphene { namespace chain { + +class database; + +class sport_object : public graphene::db::abstract_object< sport_object > +{ + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = sport_object_type; + + internationalized_string_type name; +}; + +typedef multi_index_container< + sport_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > > > > sport_object_multi_index_type; + +typedef generic_index sport_object_index; +} } // graphene::chain + +FC_REFLECT_DERIVED( graphene::chain::sport_object, (graphene::db::object), (name) ) diff --git a/libraries/chain/protocol/betting_market.cpp b/libraries/chain/protocol/betting_market.cpp new file mode 100644 index 00000000..91cbaa08 --- /dev/null +++ b/libraries/chain/protocol/betting_market.cpp @@ -0,0 +1,40 @@ +/* + * 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 { + +void betting_market_group_create_operation::validate() const +{ + FC_ASSERT( fee.amount >= 0 ); +} + +void betting_market_create_operation::validate() const +{ + FC_ASSERT( fee.amount >= 0 ); +} + + +} } // graphene::chain + diff --git a/libraries/chain/protocol/competitor.cpp b/libraries/chain/protocol/competitor.cpp new file mode 100644 index 00000000..0767720a --- /dev/null +++ b/libraries/chain/protocol/competitor.cpp @@ -0,0 +1,35 @@ +/* + * 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 { + +void competitor_create_operation::validate() const +{ + FC_ASSERT( fee.amount >= 0 ); +} + + +} } // graphene::chain + diff --git a/libraries/chain/protocol/event.cpp b/libraries/chain/protocol/event.cpp new file mode 100644 index 00000000..e2b841fc --- /dev/null +++ b/libraries/chain/protocol/event.cpp @@ -0,0 +1,35 @@ +/* + * 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 { + +void event_create_operation::validate() const +{ + FC_ASSERT( fee.amount >= 0 ); +} + + +} } // graphene::chain + diff --git a/libraries/chain/protocol/event_group.cpp b/libraries/chain/protocol/event_group.cpp new file mode 100644 index 00000000..85f74aae --- /dev/null +++ b/libraries/chain/protocol/event_group.cpp @@ -0,0 +1,35 @@ +/* + * 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 { + +void event_group_create_operation::validate() const +{ + FC_ASSERT( fee.amount >= 0 ); +} + + +} } // graphene::chain + diff --git a/libraries/chain/protocol/sport.cpp b/libraries/chain/protocol/sport.cpp new file mode 100644 index 00000000..c89f0c7e --- /dev/null +++ b/libraries/chain/protocol/sport.cpp @@ -0,0 +1,35 @@ +/* + * 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 { + +void sport_create_operation::validate() const +{ + FC_ASSERT( fee.amount >= 0 ); +} + + +} } // graphene::chain + diff --git a/libraries/chain/sport_evaluator.cpp b/libraries/chain/sport_evaluator.cpp new file mode 100644 index 00000000..763b6f62 --- /dev/null +++ b/libraries/chain/sport_evaluator.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include + +namespace graphene { namespace chain { + +void_result sport_create_evaluator::do_evaluate(const sport_create_operation& op) +{ try { + FC_ASSERT(trx_state->_is_proposed_trx); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type sport_create_evaluator::do_apply(const sport_create_operation& op) +{ try { + const sport_object& new_sport = + db().create( [&]( sport_object& sport_obj ) { + sport_obj.name = op.name; + }); + return new_sport.id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // graphene::chain diff --git a/programs/js_operation_serializer/main.cpp b/programs/js_operation_serializer/main.cpp index 61c1873e..26791a6c 100644 --- a/programs/js_operation_serializer/main.cpp +++ b/programs/js_operation_serializer/main.cpp @@ -36,6 +36,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 6d08d686..8880741e 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include @@ -1620,4 +1622,73 @@ BOOST_AUTO_TEST_CASE( buyback ) } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE( peerplays_sport_create_test ) +{ + ACTORS( (alice)(bob)(chloe)(dan)(izzy)(philbin) ); + upgrade_to_lifetime_member(philbin_id); + + try + { + { + const flat_set& active_witnesses = db.get_global_properties().active_witnesses; + // Propose the create_sport operation + { + sport_create_operation create_op; + create_op.name.insert(internationalized_string_type::value_type("en", "Ice Hockey")); + + proposal_create_operation proposal_op; + proposal_op.fee_paying_account = (*active_witnesses.begin())(db).witness_account; + proposal_op.proposed_ops.emplace_back(create_op); + proposal_op.expiration_time = db.head_block_time() + fc::days(1); + + signed_transaction tx; + tx.operations.push_back(proposal_op); + set_expiration(db, tx); + sign(tx, init_account_priv_key); + //sign( tx, philbin_private_key ); + + // Alice and Philbin signed, but asset issuer is invalid + db.push_transaction(tx); + } + + BOOST_TEST_MESSAGE( "Witness account: " << fc::json::to_pretty_string(GRAPHENE_WITNESS_ACCOUNT(db))); + + BOOST_TEST_MESSAGE("There are now " << db.get_index_type().indices().size() << " proposals"); + const proposal_object& prop = *db.get_index_type().indices().begin(); + BOOST_TEST_MESSAGE("Just created sport creation proposal " << fc::variant(prop.id).as()); + + + BOOST_CHECK_EQUAL(prop.required_active_approvals.size(), 1); // should require GRAPHENE_WITNESS_ACCOUNT only + BOOST_CHECK_EQUAL(prop.required_owner_approvals.size(), 0); + BOOST_CHECK(!prop.is_authorized_to_execute(db)); + + for (const witness_id_type& witness_id : active_witnesses) + { + BOOST_TEST_MESSAGE("Approving sport creation from witness " << fc::variant(witness_id).as()); + const witness_object& witness = witness_id(db); + const account_object& witness_account = witness.witness_account(db); + + proposal_update_operation pup; + pup.proposal = prop.id; + pup.fee_paying_account = witness_account.id; + //pup.key_approvals_to_add.insert(witness.signing_key); + pup.active_approvals_to_add.insert(witness_account.id); + + signed_transaction tx; + tx.operations.push_back( pup ); + set_expiration( db, tx ); + sign(tx, init_account_priv_key); + + db.push_transaction(tx, ~0); + if (db.get_index_type().indices().size() > 0) + { + BOOST_TEST_MESSAGE("The sport creation operation has been approved, new sport object on the blockchain is " << fc::json::to_pretty_string(*db.get_index_type().indices().begin())); + break; + } + } + } + + } FC_LOG_AND_RETHROW() +} + BOOST_AUTO_TEST_SUITE_END()