Skip to content

Commit

Permalink
Change transfer from savings to use 32 bit IDs and expand range past …
Browse files Browse the repository at this point in the history
…0-99 #239
  • Loading branch information
Michael Vandeberg committed Sep 2, 2016
1 parent 4f2dfd6 commit f19a72f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
6 changes: 6 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,12 @@ void database::process_savings_withdraws()
if( itr->complete > head_block_time() )
break;
adjust_balance( get_account( itr->to ), itr->amount );

modify( get_account( itr->from ), [&]( account_object& a )
{
a.transfer_from_savings_requests--;
});

remove( *itr );
itr = idx.begin();
}
Expand Down
6 changes: 4 additions & 2 deletions libraries/chain/include/steemit/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ namespace steemit { namespace chain {
fc::uint128_t savings_sbd_seconds; ///< total sbd * how long it has been hel
fc::time_point_sec savings_sbd_seconds_last_update; ///< the last time the sbd_seconds was updated
fc::time_point_sec savings_sbd_last_interest_payment; ///< used to pay interest at most once per month

uint8_t transfer_from_savings_requests = 0;
///@}

share_type curation_rewards = 0;
Expand Down Expand Up @@ -110,7 +112,7 @@ namespace steemit { namespace chain {
time_point_sec last_root_post = fc::time_point_sec::min();
uint32_t post_bandwidth = 0;


/** these fields are used to track password reset state */
///@{
authority pending_reset_authority;
Expand Down Expand Up @@ -368,7 +370,7 @@ FC_REFLECT_DERIVED( steemit::chain::account_object, (graphene::db::object),
(balance)
(savings_balance)
(sbd_balance)(sbd_seconds)(sbd_seconds_last_update)(sbd_last_interest_payment)
(savings_sbd_balance)(savings_sbd_seconds)(savings_sbd_seconds_last_update)(savings_sbd_last_interest_payment)
(savings_sbd_balance)(savings_sbd_seconds)(savings_sbd_seconds_last_update)(savings_sbd_last_interest_payment)(transfer_from_savings_requests)
(vesting_shares)(vesting_withdraw_rate)(next_vesting_withdrawal)(withdrawn)(to_withdraw)(withdraw_routes)
(curation_rewards)
(posting_rewards)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ namespace steemit { namespace chain {
};

/**
* This operation allows recovery_accoutn to change account_to_reset's owner authority to
* This operation allows recovery_accoutn to change account_to_reset's owner authority to
* new_owner_authority after 60 days of inactivity.
*/
struct reset_account_operation : public base_operation {
Expand Down Expand Up @@ -877,7 +877,7 @@ namespace steemit { namespace chain {

struct transfer_from_savings_operation : public base_operation {
string from;
uint16_t request_id = 0;
uint32_t request_id = 0;
string to;
asset amount;
string memo;
Expand All @@ -888,7 +888,7 @@ namespace steemit { namespace chain {

struct cancel_transfer_from_savings_operation : public base_operation {
string from;
uint16_t request_id = 0;
uint32_t request_id = 0;

void get_required_active_authorities( flat_set<string>& a )const{ a.insert( from ); }
void validate() const;
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/steemit/chain/steem_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace steemit { namespace chain {
string from;
string to;
string memo;
uint8_t request_id = 0;
uint32_t request_id = 0;
asset amount;
time_point_sec complete;
};
Expand Down Expand Up @@ -309,7 +309,7 @@ namespace steemit { namespace chain {
ordered_unique< tag< by_from_rid >,
composite_key< savings_withdraw_object,
member< savings_withdraw_object, string, &savings_withdraw_object::from >,
member< savings_withdraw_object, uint8_t, &savings_withdraw_object::request_id >
member< savings_withdraw_object, uint32_t, &savings_withdraw_object::request_id >
>
>,
ordered_unique< tag< by_to_complete >,
Expand All @@ -323,7 +323,7 @@ namespace steemit { namespace chain {
composite_key< savings_withdraw_object,
member< savings_withdraw_object, time_point_sec, &savings_withdraw_object::complete >,
member< savings_withdraw_object, string, &savings_withdraw_object::from >,
member< savings_withdraw_object, uint8_t, &savings_withdraw_object::request_id >
member< savings_withdraw_object, uint32_t, &savings_withdraw_object::request_id >
>
>
>
Expand Down
13 changes: 13 additions & 0 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,8 @@ void transfer_from_savings_evaluator::do_apply( const transfer_from_savings_oper
const auto& from = db().get_account( op.from );
const auto& to = db().get_account(op.to);

FC_ASSERT( from.transfer_from_savings_requests < STEEMIT_SAVINGS_WITHDRAW_LIMIT );

FC_ASSERT( db().get_savings_balance( from, op.amount.symbol ) >= op.amount );
db().adjust_savings_balance( from, -op.amount );
db().create<savings_withdraw_object>( [&]( savings_withdraw_object& s ) {
Expand All @@ -1730,6 +1732,11 @@ void transfer_from_savings_evaluator::do_apply( const transfer_from_savings_oper
s.request_id = op.request_id;
s.complete = db().head_block_time() + STEEMIT_SAVINGS_WITHDRAW_TIME;
});

db().modify( from, [&]( account_object& a )
{
a.transfer_from_savings_requests++;
});
}

void cancel_transfer_from_savings_evaluator::do_apply( const cancel_transfer_from_savings_operation& op )
Expand All @@ -1744,6 +1751,12 @@ void cancel_transfer_from_savings_evaluator::do_apply( const cancel_transfer_fro
const auto& swo = *itr;
db().adjust_savings_balance( db().get_account( swo.from ), swo.amount );
db().remove( swo );

const auto& from = db().get_account( op.from );
db().modify( from, [&]( account_object& a )
{
a.transfer_from_savings_requests++;
});
}

void decline_voting_rights_evaluator::do_apply( const decline_voting_rights_operation& o )
Expand Down

0 comments on commit f19a72f

Please sign in to comment.