Introducing random number object, evaluator and operations
This commit is contained in:
parent
56676b5a58
commit
d5eac3f1a7
9 changed files with 130 additions and 1 deletions
|
|
@ -115,6 +115,8 @@ add_library( graphene_chain
|
||||||
|
|
||||||
affiliate_payout.cpp
|
affiliate_payout.cpp
|
||||||
|
|
||||||
|
random_number_evaluator.cpp
|
||||||
|
|
||||||
${HEADERS}
|
${HEADERS}
|
||||||
${PROTOCOL_HEADERS}
|
${PROTOCOL_HEADERS}
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
|
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@
|
||||||
#include <graphene/chain/tournament_object.hpp>
|
#include <graphene/chain/tournament_object.hpp>
|
||||||
#include <graphene/chain/match_object.hpp>
|
#include <graphene/chain/match_object.hpp>
|
||||||
#include <graphene/chain/game_object.hpp>
|
#include <graphene/chain/game_object.hpp>
|
||||||
|
#include <graphene/chain/random_number_object.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include <graphene/chain/sport_object.hpp>
|
#include <graphene/chain/sport_object.hpp>
|
||||||
|
|
@ -77,6 +78,7 @@
|
||||||
#include <graphene/chain/event_evaluator.hpp>
|
#include <graphene/chain/event_evaluator.hpp>
|
||||||
#include <graphene/chain/betting_market_evaluator.hpp>
|
#include <graphene/chain/betting_market_evaluator.hpp>
|
||||||
#include <graphene/chain/tournament_evaluator.hpp>
|
#include <graphene/chain/tournament_evaluator.hpp>
|
||||||
|
#include <graphene/chain/random_number_evaluator.hpp>
|
||||||
|
|
||||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||||
|
|
||||||
|
|
@ -169,6 +171,8 @@ const uint8_t betting_market_position_object::type_id;
|
||||||
const uint8_t global_betting_statistics_object::space_id;
|
const uint8_t global_betting_statistics_object::space_id;
|
||||||
const uint8_t global_betting_statistics_object::type_id;
|
const uint8_t global_betting_statistics_object::type_id;
|
||||||
|
|
||||||
|
const uint8_t random_number_object::space_id;
|
||||||
|
const uint8_t random_number_object::type_id;
|
||||||
|
|
||||||
void database::initialize_evaluators()
|
void database::initialize_evaluators()
|
||||||
{
|
{
|
||||||
|
|
@ -243,6 +247,7 @@ void database::initialize_evaluators()
|
||||||
register_evaluator<lottery_reward_evaluator>();
|
register_evaluator<lottery_reward_evaluator>();
|
||||||
register_evaluator<lottery_end_evaluator>();
|
register_evaluator<lottery_end_evaluator>();
|
||||||
register_evaluator<sweeps_vesting_claim_evaluator>();
|
register_evaluator<sweeps_vesting_claim_evaluator>();
|
||||||
|
register_evaluator<random_number_store_evaluator>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::initialize_indexes()
|
void database::initialize_indexes()
|
||||||
|
|
@ -313,6 +318,7 @@ void database::initialize_indexes()
|
||||||
|
|
||||||
add_index< primary_index<lottery_balance_index > >();
|
add_index< primary_index<lottery_balance_index > >();
|
||||||
add_index< primary_index<sweeps_vesting_balance_index > >();
|
add_index< primary_index<sweeps_vesting_balance_index > >();
|
||||||
|
add_index< primary_index<random_number_index > >();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,9 @@ struct get_impacted_account_visitor
|
||||||
void operator()( const sweeps_vesting_claim_operation& op ) {
|
void operator()( const sweeps_vesting_claim_operation& op ) {
|
||||||
_impacted.insert( op.account );
|
_impacted.insert( op.account );
|
||||||
}
|
}
|
||||||
|
void operator()( const random_number_store_operation& op ) {
|
||||||
|
_impacted.insert( op.account );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void graphene::chain::operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
|
void graphene::chain::operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
#include <graphene/chain/protocol/event.hpp>
|
#include <graphene/chain/protocol/event.hpp>
|
||||||
#include <graphene/chain/protocol/betting_market.hpp>
|
#include <graphene/chain/protocol/betting_market.hpp>
|
||||||
#include <graphene/chain/protocol/tournament.hpp>
|
#include <graphene/chain/protocol/tournament.hpp>
|
||||||
|
#include <graphene/chain/protocol/random_number.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
|
@ -135,7 +136,8 @@ namespace graphene { namespace chain {
|
||||||
ticket_purchase_operation,
|
ticket_purchase_operation,
|
||||||
lottery_reward_operation,
|
lottery_reward_operation,
|
||||||
lottery_end_operation,
|
lottery_end_operation,
|
||||||
sweeps_vesting_claim_operation
|
sweeps_vesting_claim_operation,
|
||||||
|
random_number_store_operation
|
||||||
> operation;
|
> operation;
|
||||||
|
|
||||||
/// @} // operations group
|
/// @} // operations group
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
#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;
|
||||||
|
time_point_sec timestamp;
|
||||||
|
uint64_t 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)
|
||||||
|
(timestamp)
|
||||||
|
(random_number)
|
||||||
|
(data) )
|
||||||
|
|
||||||
|
|
@ -171,6 +171,7 @@ namespace graphene { namespace chain {
|
||||||
betting_market_group_object_type,
|
betting_market_group_object_type,
|
||||||
betting_market_object_type,
|
betting_market_object_type,
|
||||||
bet_object_type,
|
bet_object_type,
|
||||||
|
random_number_object_type,
|
||||||
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -230,6 +231,7 @@ namespace graphene { namespace chain {
|
||||||
class betting_market_group_object;
|
class betting_market_group_object;
|
||||||
class betting_market_object;
|
class betting_market_object;
|
||||||
class bet_object;
|
class bet_object;
|
||||||
|
class random_number_object;
|
||||||
|
|
||||||
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
||||||
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
|
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
|
||||||
|
|
@ -256,6 +258,7 @@ namespace graphene { namespace chain {
|
||||||
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_group_object_type, betting_market_group_object> betting_market_group_id_type;
|
||||||
typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type;
|
typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type;
|
||||||
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
|
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
|
||||||
|
typedef object_id< protocol_ids, random_number_object_type, random_number_object> random_number_id_type;
|
||||||
|
|
||||||
// implementation types
|
// implementation types
|
||||||
class global_property_object;
|
class global_property_object;
|
||||||
|
|
@ -436,6 +439,7 @@ FC_REFLECT_ENUM( graphene::chain::object_type,
|
||||||
(betting_market_group_object_type)
|
(betting_market_group_object_type)
|
||||||
(betting_market_object_type)
|
(betting_market_object_type)
|
||||||
(bet_object_type)
|
(bet_object_type)
|
||||||
|
(random_number_object_type)
|
||||||
(OBJECT_TYPE_COUNT)
|
(OBJECT_TYPE_COUNT)
|
||||||
)
|
)
|
||||||
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
||||||
|
|
@ -505,6 +509,7 @@ FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type )
|
FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type )
|
||||||
|
FC_REFLECT_TYPENAME( graphene::chain::random_number_id_type )
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::void_t, )
|
FC_REFLECT( graphene::chain::void_t, )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
#include <graphene/chain/database.hpp>
|
||||||
|
#include <graphene/chain/evaluator.hpp>
|
||||||
|
#include <graphene/chain/protocol/operations.hpp>
|
||||||
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
class random_number_store_evaluator : public evaluator<random_number_store_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
|
||||||
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
using namespace graphene::db;
|
||||||
|
|
||||||
|
class random_number_object : public abstract_object<random_number_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 */
|
||||||
|
uint64_t random_number; /* random number */
|
||||||
|
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<by_id>,
|
||||||
|
member<object, object_id_type, &object::id>
|
||||||
|
>,
|
||||||
|
ordered_non_unique< tag<by_account>,
|
||||||
|
member<random_number_object, account_id_type, &random_number_object::account>
|
||||||
|
>,
|
||||||
|
ordered_non_unique< tag<by_timestamp>,
|
||||||
|
member<random_number_object, time_point_sec, &random_number_object::timestamp>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
using random_number_index = generic_index<random_number_object, random_number_multi_index_type>;
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
|
FC_REFLECT_DERIVED( graphene::chain::random_number_object, (graphene::db::object),
|
||||||
|
(account) (timestamp)
|
||||||
|
(random_number) (data) )
|
||||||
|
|
||||||
24
libraries/chain/random_number_evaluator.cpp
Normal file
24
libraries/chain/random_number_evaluator.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include <graphene/chain/random_number_evaluator.hpp>
|
||||||
|
#include <graphene/chain/random_number_object.hpp>
|
||||||
|
|
||||||
|
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>( [&]( random_number_object& obj ) {
|
||||||
|
//obj.account = op.account;
|
||||||
|
//obj.timestamp = op.timestamp;
|
||||||
|
//obj.random_number = op.random_number;
|
||||||
|
//obj.data = op.data;
|
||||||
|
});
|
||||||
|
return new_random_number_object.id;
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
Loading…
Reference in a new issue