From ad11c454154135513cf1b6617d7f9bba1f4d49fa Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Wed, 16 Aug 2017 18:56:23 -0400 Subject: [PATCH] Pretty-print bet place, fill, refund, cancellation --- .../wallet/include/graphene/wallet/wallet.hpp | 20 ++++++++- libraries/wallet/wallet.cpp | 44 +++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 3d7decfb..db5d818c 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1573,6 +1573,13 @@ class wallet_api asset get_total_matched_bet_amount_for_betting_market_group(betting_market_group_id_type group_id); std::vector get_events_containing_sub_string(const std::string& sub_string, const std::string& language); + + /** Get an order book for a betting market, with orders aggregated into bins with similar + * odds + * + * @param betting_market_id the betting market + * @param precision the number of digits of precision for binning + */ binned_order_book get_binned_order_book(graphene::chain::betting_market_id_type betting_market_id, int32_t precision); vector list_sports() const; @@ -1679,13 +1686,22 @@ class wallet_api fc::optional payout_condition, bool broadcast = false); - signed_transaction place_bet(string betting_account, + /** Place a bet + * @param bettor the account placing the bet + * @param betting_market_id the market on which to bet + * @param back_or_lay back or lay + * @param amount the amount to bet + * @param asset_symbol the asset to bet with (must be the same as required by the betting market group) + * @param backer_multiplier the odds (use 2.0 for a 1:1 bet) + * @param broadcast true to broadcast the transaction + */ + signed_transaction place_bet(string bettor, betting_market_id_type betting_market_id, bet_type back_or_lay, string amount, string asset_symbol, double backer_multiplier, - bool broadcast /*= false*/); + bool broadcast = false); signed_transaction propose_resolve_betting_market_group( const string& proposing_account, diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 80e6532b..d50c937c 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -137,6 +137,10 @@ public: std::string operator()(const asset_create_operation& op)const; std::string operator()(const asset_dividend_distribution_operation& op)const; std::string operator()(const tournament_payout_operation& op)const; + std::string operator()(const bet_place_operation& op)const; + std::string operator()(const bet_matched_operation& op)const; + std::string operator()(const bet_canceled_operation& op)const; + std::string operator()(const bet_adjusted_operation& op)const; }; template @@ -3326,6 +3330,46 @@ std::string operation_printer::operator()(const tournament_payout_operation& op) return ""; } +std::string operation_printer::operator()(const bet_place_operation& op)const +{ + auto fee_asset = wallet.get_asset(op.fee.asset_id); + auto asset = wallet.get_asset(op.amount_to_bet.asset_id); + auto bettor = wallet.get_account(op.bettor_id); + + out << bettor.name << " placed a " << fc::json::to_string(op.back_or_lay) << " bet for " + << asset.amount_to_pretty_string(op.amount_to_bet) << " at odds " << ((double)op.backer_multiplier / GRAPHENE_BETTING_ODDS_PRECISION) + << " on market " << fc::json::to_string(op.betting_market_id) + << " fee: " << fee_asset.amount_to_pretty_string(op.fee); + return ""; +} + +std::string operation_printer::operator()(const bet_matched_operation& op)const +{ + auto asset = wallet.get_asset(op.amount_bet.asset_id); + auto bettor = wallet.get_account(op.bettor_id); + + out << " " << bettor.name << "'s bet " << fc::json::to_string(op.bet_id) << " matched " << asset.amount_to_pretty_string(op.amount_bet) << " at odds " << ((double)op.backer_multiplier / GRAPHENE_BETTING_ODDS_PRECISION); + return ""; +} + +std::string operation_printer::operator()(const bet_canceled_operation& op)const +{ + auto asset = wallet.get_asset(op.stake_returned.asset_id); + auto bettor = wallet.get_account(op.bettor_id); + + out << " " << bettor.name << "'s bet " << fc::json::to_string(op.bet_id) << " was canceled, " << asset.amount_to_pretty_string(op.stake_returned) << " returned"; + return ""; +} + +std::string operation_printer::operator()(const bet_adjusted_operation& op)const +{ + auto asset = wallet.get_asset(op.stake_returned.asset_id); + auto bettor = wallet.get_account(op.bettor_id); + + out << " " << bettor.name << "'s bet " << fc::json::to_string(op.bet_id) << " was adjusted, " << asset.amount_to_pretty_string(op.stake_returned) << " returned"; + return ""; +} + std::string operation_result_printer::operator()(const void_result& x) const { return "";