Skip to content

Commit

Permalink
Merge pull request #456 from steemit/381-vop-fixes
Browse files Browse the repository at this point in the history
381 vop fixes
  • Loading branch information
Michael Vandeberg committed Sep 22, 2016
2 parents 7feb97a + 1927ce7 commit 9ff0fde
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 16 deletions.
24 changes: 17 additions & 7 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/steemit/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -897,6 +898,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;
Expand All @@ -912,6 +926,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) )
Expand Down Expand Up @@ -963,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) )
Expand Down
50 changes: 46 additions & 4 deletions libraries/plugins/account_history/account_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down

0 comments on commit 9ff0fde

Please sign in to comment.