From f19a72f45246a67bfcfbe7a3e4d2e064e7e389cc Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Fri, 2 Sep 2016 15:12:27 -0400 Subject: [PATCH] Change transfer from savings to use 32 bit IDs and expand range past 0-99 #239 --- libraries/chain/database.cpp | 6 ++++++ .../chain/include/steemit/chain/account_object.hpp | 6 ++++-- .../steemit/chain/protocol/steem_operations.hpp | 6 +++--- .../chain/include/steemit/chain/steem_objects.hpp | 6 +++--- libraries/chain/steem_evaluator.cpp | 13 +++++++++++++ 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 629c87dbbf..0fd9779f68 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -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(); } diff --git a/libraries/chain/include/steemit/chain/account_object.hpp b/libraries/chain/include/steemit/chain/account_object.hpp index 0b91052dd3..c6c077ffb9 100644 --- a/libraries/chain/include/steemit/chain/account_object.hpp +++ b/libraries/chain/include/steemit/chain/account_object.hpp @@ -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; @@ -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; @@ -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) diff --git a/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp b/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp index 7a29c07bad..8fd213d057 100644 --- a/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp +++ b/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp @@ -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 { @@ -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; @@ -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& a )const{ a.insert( from ); } void validate() const; diff --git a/libraries/chain/include/steemit/chain/steem_objects.hpp b/libraries/chain/include/steemit/chain/steem_objects.hpp index 30022c1692..3c6ed9b5b9 100755 --- a/libraries/chain/include/steemit/chain/steem_objects.hpp +++ b/libraries/chain/include/steemit/chain/steem_objects.hpp @@ -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; }; @@ -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 >, @@ -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 > > > > diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index 9f6570b2e4..6fff5505f8 100644 --- a/libraries/chain/steem_evaluator.cpp +++ b/libraries/chain/steem_evaluator.cpp @@ -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& s ) { @@ -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 ) @@ -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 )