From ece936fcb2a7ee23f64d070dc743e8e80b081680 Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Wed, 21 Sep 2016 16:42:03 -0400 Subject: [PATCH 1/2] Add savings and escrow ops to unfiltered account history #381 --- .../steemit/chain/protocol/operations.hpp | 3 +- .../chain/protocol/steem_operations.hpp | 14 ++++++ .../account_history_plugin.cpp | 50 +++++++++++++++++-- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/libraries/chain/include/steemit/chain/protocol/operations.hpp b/libraries/chain/include/steemit/chain/protocol/operations.hpp index 4379e37636..59adeb1a59 100644 --- a/libraries/chain/include/steemit/chain/protocol/operations.hpp +++ b/libraries/chain/include/steemit/chain/protocol/operations.hpp @@ -69,7 +69,8 @@ namespace steemit { namespace chain { interest_operation, fill_vesting_withdraw_operation, fill_order_operation, - shutdown_witness_operation + shutdown_witness_operation, + fill_transfer_from_savings_operation > operation; /*void operation_get_required_authorities( const operation& op, diff --git a/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp b/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp index c8e7b77232..f34ac40a44 100644 --- a/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp +++ b/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp @@ -897,6 +897,19 @@ namespace steemit { namespace chain { void validate() const; }; + struct fill_transfer_from_savings_operation : public virtual_operation + { + fill_transfer_from_savings_operation() {} + fill_transfer_from_savings_operation( const string& f, const string& t, const asset& a, const uint32_t r, const string& m ) + :from(f), to(t), amount(a), request_id(r), memo(m) {} + + string from; + string to; + asset amount; + uint32_t request_id = 0; + string memo; + }; + struct decline_voting_rights_operation : public base_operation { string account; @@ -912,6 +925,7 @@ namespace steemit { namespace chain { FC_REFLECT( steemit::chain::transfer_to_savings_operation, (from)(to)(amount)(memo) ) FC_REFLECT( steemit::chain::transfer_from_savings_operation, (from)(request_id)(to)(amount)(memo) ) FC_REFLECT( steemit::chain::cancel_transfer_from_savings_operation, (from)(request_id) ) +FC_REFLECT( steemit::chain::fill_transfer_from_savings_operation, (from)(to)(amount)(request_id)(memo) ) FC_REFLECT( steemit::chain::reset_account_operation, (reset_account)(account_to_reset)(new_owner_authority) ) FC_REFLECT( steemit::chain::set_reset_account_operation, (account)(reset_account) ) diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index d8b0906252..cf0a9785a7 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -98,16 +98,58 @@ struct operation_visitor_filter : operation_visitor { void operator()( const limit_order_cancel_operation& )const {} void operator()( const pow_operation& )const {} - void operator()( const transfer_operation& op )const { + void operator()( const transfer_operation& op )const + { operation_visitor::operator()( op ); } - void operator()( const transfer_to_vesting_operation& op )const { + + void operator()( const transfer_to_vesting_operation& op )const + { + operation_visitor::operator()( op ); + } + + void operator()( const account_create_operation& op )const + { + operation_visitor::operator()( op ); + } + + void operator()( const account_update_operation& op )const + { + operation_visitor::operator()( op ); + } + + void operator()( const transfer_to_savings_operation& op )const + { + operation_visitor::operator()( op ); + } + + void operator()( const transfer_from_savings_operation& op )const + { + operation_visitor::operator()( op ); + } + + void operator()( const cancel_transfer_from_savings_operation& op )const + { + operation_visitor::operator()( op ); + } + + void operator()( const escrow_transfer_operation& op )const + { + operation_visitor::operator()( op ); + } + + void operator()( const escrow_dispute_operation& op )const + { operation_visitor::operator()( op ); } - void operator()( const account_create_operation& op )const { + + void operator()( const escrow_release_operation& op )const + { operation_visitor::operator()( op ); } - void operator()( const account_update_operation& op )const { + + void operator()( const escrow_approve_operation& op )const + { operation_visitor::operator()( op ); } From 1927ce7bb43f57fab9502b4ce4d50b23fcd0604c Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Wed, 21 Sep 2016 16:42:36 -0400 Subject: [PATCH 2/2] Add liquid steem to author reward virtual op --- libraries/chain/database.cpp | 24 +++++++++++++------ .../chain/include/steemit/chain/database.hpp | 2 +- .../chain/protocol/steem_operations.hpp | 7 +++--- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index e843db63c2..a2e16adb40 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -993,12 +993,14 @@ uint32_t database::get_slot_at_time(fc::time_point_sec when)const * Converts STEEM into sbd and adds it to to_account while reducing the STEEM supply * by STEEM and increasing the sbd supply by the specified amount. */ -asset database::create_sbd( const account_object& to_account, asset steem ) +std::pair< asset, asset > database::create_sbd( const account_object& to_account, asset steem ) { + std::pair< asset, asset > assets( asset( 0, SBD_SYMBOL ), asset( 0, STEEM_SYMBOL ) ); + try { if( steem.amount == 0 ) - return asset(0, SBD_SYMBOL); + return assets; const auto& median_price = get_feed_history().current_median_history; const auto& gpo = get_dynamic_global_properties(); @@ -1014,15 +1016,18 @@ asset database::create_sbd( const account_object& to_account, asset steem ) adjust_balance( to_account, asset( to_steem, STEEM_SYMBOL ) ); adjust_supply( asset( -to_sbd, STEEM_SYMBOL ) ); adjust_supply( sbd ); - return sbd; + assets.first = sbd; + assets.second = to_steem; } else { adjust_balance( to_account, steem ); - return steem; + assets.second = steem; } } FC_CAPTURE_LOG_AND_RETHROW( (to_account.name)(steem) ) + + return assets; } /** @@ -1966,17 +1971,20 @@ void database::cashout_comment_helper( const comment_object& comment ) const auto& author = get_account( comment.author ); auto vest_created = create_vesting( author, vesting_steem ); - auto sbd_created = create_sbd( author, sbd_steem ); + auto sbd_payout = create_sbd( author, sbd_steem ); - if( sbd_created.symbol == SBD_SYMBOL ) + adjust_total_payout( comment, sbd_payout.first + to_sbd( sbd_payout.second + asset( vesting_steem, STEEM_SYMBOL ) ), to_sbd( asset( reward_tokens.to_uint64() - author_tokens, STEEM_SYMBOL ) ) ); + + /*if( sbd_created.symbol == SBD_SYMBOL ) adjust_total_payout( comment, sbd_created + to_sbd( asset( vesting_steem, STEEM_SYMBOL ) ), to_sbd( asset( reward_tokens.to_uint64() - author_tokens, STEEM_SYMBOL ) ) ); else adjust_total_payout( comment, to_sbd( asset( vesting_steem + sbd_steem, STEEM_SYMBOL ) ), to_sbd( asset( reward_tokens.to_uint64() - author_tokens, STEEM_SYMBOL ) ) ); + */ // stats only.. TODO: Move to plugin... total_payout = to_sbd( asset( reward_tokens.to_uint64(), STEEM_SYMBOL ) ); - push_virtual_operation( author_reward_operation( comment.author, comment.permlink, sbd_created, vest_created ) ); + push_virtual_operation( author_reward_operation( comment.author, comment.permlink, sbd_payout.first, sbd_payout.second, vest_created ) ); push_virtual_operation( comment_reward_operation( comment.author, comment.permlink, total_payout ) ); #ifndef IS_LOW_MEM @@ -2136,6 +2144,8 @@ void database::process_savings_withdraws() a.savings_withdraw_requests--; }); + push_virtual_operation( fill_transfer_from_savings_operation( itr->from, itr->to, itr->amount, itr->request_id, itr->memo) ); + remove( *itr ); itr = idx.begin(); } diff --git a/libraries/chain/include/steemit/chain/database.hpp b/libraries/chain/include/steemit/chain/database.hpp index 8b7fb37fb9..fdedfdcb5b 100644 --- a/libraries/chain/include/steemit/chain/database.hpp +++ b/libraries/chain/include/steemit/chain/database.hpp @@ -250,7 +250,7 @@ namespace steemit { namespace chain { uint32_t get_slot_at_time(fc::time_point_sec when)const; /** @return the sbd created and deposited to_account, may return STEEM if there is no median feed */ - asset create_sbd( const account_object& to_account, asset steem ); + std::pair< asset, asset > create_sbd( const account_object& to_account, asset steem ); asset create_vesting( const account_object& to_account, asset steem ); void adjust_total_payout( const comment_object& a, const asset& sbd, const asset& curator_sbd_value ); diff --git a/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp b/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp index f34ac40a44..a4b1755f6b 100644 --- a/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp +++ b/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp @@ -126,11 +126,12 @@ namespace steemit { namespace chain { struct author_reward_operation : public virtual_operation { author_reward_operation(){} - author_reward_operation( const string& a, const string& p, const asset& s, const asset& v ) - :author(a),permlink(p),sbd_payout(s),vesting_payout(v){} + author_reward_operation( const string& a, const string& p, const asset& s, const asset& st, const asset& v ) + :author(a),permlink(p),sbd_payout(s),steem_payout(st),vesting_payout(v){} string author; string permlink; asset sbd_payout; + asset steem_payout; asset vesting_payout; }; @@ -977,7 +978,7 @@ FC_REFLECT( steemit::chain::limit_order_create2_operation, (owner)(orderid)(amou FC_REFLECT( steemit::chain::fill_order_operation, (current_owner)(current_orderid)(current_pays)(open_owner)(open_orderid)(open_pays) ); FC_REFLECT( steemit::chain::limit_order_cancel_operation, (owner)(orderid) ) -FC_REFLECT( steemit::chain::author_reward_operation, (author)(permlink)(sbd_payout)(vesting_payout) ) +FC_REFLECT( steemit::chain::author_reward_operation, (author)(permlink)(sbd_payout)(steem_payout)(vesting_payout) ) FC_REFLECT( steemit::chain::curation_reward_operation, (curator)(reward)(comment_author)(comment_permlink) ) FC_REFLECT( steemit::chain::comment_reward_operation, (author)(permlink)(payout) ) FC_REFLECT( steemit::chain::fill_convert_request_operation, (owner)(requestid)(amount_in)(amount_out) )