implement bet_cancel_operation

This commit is contained in:
SynaptiCAD User 2017-03-22 12:03:08 -04:00
parent 46ef911f8e
commit c42a56d332
11 changed files with 83 additions and 2 deletions

View file

@ -210,6 +210,7 @@ struct get_impacted_account_visitor
void operator()( const betting_market_group_create_operation& op ) {}
void operator()( const betting_market_create_operation& op ) {}
void operator()( const bet_place_operation& op ) {}
void operator()( const bet_cancel_operation& op ) {}
};

View file

@ -10,6 +10,7 @@ file(GLOB HEADERS "include/graphene/chain/*.hpp")
if( GRAPHENE_DISABLE_UNITY_BUILD )
set( GRAPHENE_DB_FILES
db_balance.cpp
db_bet.cpp
db_block.cpp
db_debug.cpp
db_getter.cpp

View file

@ -94,6 +94,7 @@ object_id_type betting_market_create_evaluator::do_apply(const betting_market_cr
void_result bet_place_evaluator::do_evaluate(const bet_place_operation& op)
{ try {
<<<<<<< 46ef911f8ec2454ea00507dabc843a994b1fc842
const database& d = db();
_betting_market = &op.betting_market_id(d);
@ -139,4 +140,19 @@ object_id_type bet_place_evaluator::do_apply(const bet_place_operation& op)
return new_bet.id;
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result bet_cancel_evaluator::do_evaluate(const bet_cancel_operation& op)
{ try {
FC_ASSERT( db().find_object(op.bettor_id), "Invalid bettor account specified" );
FC_ASSERT( db().find_object(op.bet_to_cancel), "Invalid bet specified" );
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result bet_cancel_evaluator::do_apply(const bet_cancel_operation& op)
{ try {
const bet_object& bet_to_cancel = op.bet_to_cancel( db() );
db().cancel_bet(bet_to_cancel);
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
} } // graphene::chain

View file

@ -23,6 +23,7 @@
*/
#include <fc/smart_ref_impl.hpp>
#include "db_balance.cpp"
#include "db_bet.cpp"
#include "db_block.cpp"
#include "db_debug.cpp"
#include "db_getter.cpp"

View file

@ -0,0 +1,24 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/betting_market_object.hpp>
namespace graphene { namespace chain {
void database::cancel_bet( const bet_object& bet, bool create_virtual_op )
{
share_type amount_to_refund = bet.amount_to_bet;
//TODO: update global statistics
adjust_balance(bet.bettor_id, amount_to_refund); //return unmatched stake
//TODO: do special fee accounting as required
if (create_virtual_op)
{
bet_cancel_operation vop;
vop.bettor_id = bet.bettor_id;
vop.bet_to_cancel = bet.id;
push_applied_operation(vop);
}
remove(bet);
}
} }

View file

@ -64,4 +64,13 @@ namespace graphene { namespace chain {
const asset_object* _asset;
};
class bet_cancel_evaluator : public evaluator<bet_cancel_evaluator>
{
public:
typedef bet_cancel_operation operation_type;
void_result do_evaluate( const bet_cancel_operation& o );
void_result do_apply( const bet_cancel_operation& o );
};
} } // graphene::chain

View file

@ -323,6 +323,9 @@ namespace graphene { namespace chain {
void debug_dump();
//////////////////// db_bet.cpp //////////////////////
void cancel_bet(const bet_object& bet, bool create_virtual_op = true);
//////////////////// db_market.cpp ////////////////////
/// @{ @group Market Helpers

View file

@ -144,6 +144,22 @@ struct bet_place_operation : public base_operation
void validate()const;
};
struct bet_cancel_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
asset fee;
/// the bettor who is cancelling the bet
account_id_type bettor_id;
/// the bet being canceled
bet_id_type bet_to_cancel;
extensions_type extensions;
account_id_type fee_payer()const { return bettor_id; }
void validate()const;
};
} }
@ -174,3 +190,6 @@ FC_REFLECT_ENUM( graphene::chain::bet_type, (back)(lay) )
FC_REFLECT( graphene::chain::bet_place_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::bet_place_operation,
(fee)(bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(amount_reserved_for_fees)(back_or_lay)(extensions) )
FC_REFLECT( graphene::chain::bet_cancel_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::bet_cancel_operation, (bettor_id) (bet_to_cancel) (extensions) )

View file

@ -103,7 +103,8 @@ namespace graphene { namespace chain {
event_create_operation,
betting_market_group_create_operation,
betting_market_create_operation,
bet_place_operation
bet_place_operation,
bet_cancel_operation
> operation;
/// @} // operations group

View file

@ -45,6 +45,12 @@ void bet_place_operation::validate() const
FC_ASSERT( fee.amount >= 0 );
}
void bet_cancel_operation::validate() const
{
FC_ASSERT( fee.amount >= 0 );
}
} } // graphene::chain

@ -1 +1 @@
Subproject commit 9d408aa53267834542279490eac4c25878107967
Subproject commit 57d14c7de849c567d753fc5cab5465d68602ff95