From d65f20a89fc941d6b06643c8a78846a1aa1d104f Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Thu, 3 Oct 2019 16:38:40 -0300
Subject: [PATCH] changes to have separate methods and single withdrawl fee for
multiple vest objects
---
.../chain/vesting_balance_evaluator.hpp | 1 +
libraries/chain/vesting_balance_evaluator.cpp | 26 ++++++-
.../wallet/include/graphene/wallet/wallet.hpp | 21 ++++-
libraries/wallet/wallet.cpp | 78 +++++++++++++++----
4 files changed, 107 insertions(+), 19 deletions(-)
diff --git a/libraries/chain/include/graphene/chain/vesting_balance_evaluator.hpp b/libraries/chain/include/graphene/chain/vesting_balance_evaluator.hpp
index fccfbb75..9bb7520e 100644
--- a/libraries/chain/include/graphene/chain/vesting_balance_evaluator.hpp
+++ b/libraries/chain/include/graphene/chain/vesting_balance_evaluator.hpp
@@ -46,6 +46,7 @@ class vesting_balance_withdraw_evaluator : public evaluator();
+
+ const time_point_sec now = d.head_block_time();
+
+ if(now >= (fc::time_point_sec(1570114100)) )
+ {
+ if(oper.fee.amount == 0)
+ {
+ trx_state->skip_fee_schedule_check = true;
+ trx_state->skip_fee = true;
+ }
+ }
+ //check_required_authorities(op);
+ auto result = evaluate( oper );
+
+ if( apply ) result = this->apply( oper );
+ return result;
+} FC_CAPTURE_AND_RETHROW() }
+
void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balance_withdraw_operation& op )
{ try {
const database& d = db();
@@ -125,7 +148,7 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan
FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "", ("now", now)("op", op)("vbo", vbo) );
assert( op.amount <= vbo.balance ); // is_withdraw_allowed should fail before this check is reached
- /* const account_object& owner_account = */ op.owner( d );
+ /* const account_object& owner_account = op.owner( d ); */
// TODO: Check asset authorizations and withdrawals
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
@@ -133,6 +156,7 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan
void_result vesting_balance_withdraw_evaluator::do_apply( const vesting_balance_withdraw_operation& op )
{ try {
database& d = db();
+
const time_point_sec now = d.head_block_time();
const vesting_balance_object& vbo = op.vesting_balance( d );
diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp
index 2b8012b4..8a15fec0 100644
--- a/libraries/wallet/include/graphene/wallet/wallet.hpp
+++ b/libraries/wallet/include/graphene/wallet/wallet.hpp
@@ -1343,20 +1343,32 @@ class wallet_api
vector< vesting_balance_object_with_info > get_vesting_balances( string account_name );
/**
- * Withdraw a vesting balance.
+ * Withdraw a normal(old) vesting balance.
*
* @param witness_name The account name of the witness, also accepts account ID or vesting balance ID type.
* @param amount The amount to withdraw.
* @param asset_symbol The symbol of the asset to withdraw.
* @param broadcast true if you wish to broadcast the transaction
- * @param vb_type vestig balance type to withdraw 0-OLD, 1-GPOS, 2-SONS(if required)
*/
signed_transaction withdraw_vesting(
string witness_name,
string amount,
string asset_symbol,
- bool broadcast = false,
- uint8_t vb_type = 0);
+ bool broadcast = false);
+
+ /**
+ * Withdraw a GPOS vesting balance.
+ *
+ * @param account_name The account name of the witness/user, also accepts account ID or vesting balance ID type.
+ * @param amount The amount to withdraw.
+ * @param asset_symbol The symbol of the asset to withdraw.
+ * @param broadcast true if you wish to broadcast the transaction
+ */
+ signed_transaction withdraw_GPOS_vesting_balance(
+ string account_name,
+ string amount,
+ string asset_symbol,
+ bool broadcast = false);
/** Vote for a given committee_member.
*
@@ -1966,6 +1978,7 @@ FC_API( graphene::wallet::wallet_api,
(update_worker_votes)
(get_vesting_balances)
(withdraw_vesting)
+ (withdraw_GPOS_vesting_balance)
(vote_for_committee_member)
(vote_for_witness)
(update_witness_votes)
diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp
index 185fc7d1..b6aa2cbf 100644
--- a/libraries/wallet/wallet.cpp
+++ b/libraries/wallet/wallet.cpp
@@ -1963,23 +1963,57 @@ public:
string witness_name,
string amount,
string asset_symbol,
- bool broadcast = false,
- uint8_t vb_type = 0 )
+ bool broadcast = false )
{ try {
asset_object asset_obj = get_asset( asset_symbol );
- vector< vesting_balance_object > vbos;
fc::optional vbid = maybe_id(witness_name);
if( !vbid )
+ {
+ witness_object wit = get_witness( witness_name );
+ FC_ASSERT( wit.pay_vb );
+ vbid = wit.pay_vb;
+ }
+
+ vesting_balance_object vbo = get_object< vesting_balance_object >( *vbid );
+
+ if(vbo.balance_type != vesting_balance_type::normal)
+ FC_THROW("Allowed to withdraw only Normal type vest balances with this method");
+
+ vesting_balance_withdraw_operation vesting_balance_withdraw_op;
+
+ vesting_balance_withdraw_op.vesting_balance = *vbid;
+ vesting_balance_withdraw_op.owner = vbo.owner;
+ vesting_balance_withdraw_op.amount = asset_obj.amount_from_string(amount);
+
+ signed_transaction tx;
+ tx.operations.push_back( vesting_balance_withdraw_op );
+ set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees );
+ tx.validate();
+
+ return sign_transaction( tx, broadcast );
+ } FC_CAPTURE_AND_RETHROW( (witness_name)(amount) )
+ }
+
+ signed_transaction withdraw_GPOS_vesting_balance(
+ string account_name,
+ string amount,
+ string asset_symbol,
+ bool broadcast = false)
+ { try {
+ asset_object asset_obj = get_asset( asset_symbol );
+ vector< vesting_balance_object > vbos;
+ fc::optional vbid = maybe_id(account_name);
+ if( !vbid )
{
//Changes done to retrive user account/witness account based on account name
- fc::optional acct_id = maybe_id( witness_name );
+ fc::optional acct_id = maybe_id( account_name );
if( !acct_id )
- acct_id = get_account( witness_name ).id;
+ acct_id = get_account( account_name ).id;
vbos = _remote_db->get_vesting_balances( *acct_id );
if( vbos.size() == 0 )
{
- witness_object wit = get_witness( witness_name );
+ witness_object wit = get_witness( account_name );
FC_ASSERT( wit.pay_vb );
vbid = wit.pay_vb;
}
@@ -1991,14 +2025,22 @@ public:
signed_transaction tx;
asset withdraw_amount = asset_obj.amount_from_string(amount);
-
+ bool onetime_fee_paid = false;
+
for(const vesting_balance_object& vbo: vbos )
{
- if((vb_type == (uint8_t)vbo.balance_type) && vbo.balance.amount > 0)
+ if((vbo.balance_type == vesting_balance_type::gpos) && vbo.balance.amount > 0)
{
fc::optional vest_id = vbo.id;
vesting_balance_withdraw_operation vesting_balance_withdraw_op;
+ // Since there are multiple vesting objects, below logic with vesting_balance_evaluator.cpp changes will
+ // deduct fee from single object and set withdrawl fee to 0 for rest of objects based on requested amount.
+ if(onetime_fee_paid)
+ vesting_balance_withdraw_op.fee = asset( 0, asset_id_type() );
+ else
+ vesting_balance_withdraw_op.fee = _remote_db->get_global_properties().parameters.current_fees->calculate_fee(vesting_balance_withdraw_op);
+
vesting_balance_withdraw_op.vesting_balance = *vest_id;
vesting_balance_withdraw_op.owner = vbo.owner;
if(withdraw_amount.amount >= vbo.balance.amount)
@@ -2015,17 +2057,17 @@ public:
}
tx.operations.push_back( vesting_balance_withdraw_op );
+ onetime_fee_paid = true;
}
}
if( withdraw_amount.amount > 0)
- FC_THROW("Account has insufficient balance to withdraw");
+ FC_THROW("Account has NO or Insufficient balance to withdraw");
- set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees );
tx.validate();
return sign_transaction( tx, broadcast );
- } FC_CAPTURE_AND_RETHROW( (witness_name)(amount) )
+ } FC_CAPTURE_AND_RETHROW( (account_name)(amount) )
}
signed_transaction vote_for_committee_member(string voting_account,
@@ -4083,10 +4125,18 @@ signed_transaction wallet_api::withdraw_vesting(
string witness_name,
string amount,
string asset_symbol,
- bool broadcast,
- uint8_t vb_type)
+ bool broadcast)
{
- return my->withdraw_vesting( witness_name, amount, asset_symbol, broadcast, vb_type );
+ return my->withdraw_vesting( witness_name, amount, asset_symbol, broadcast );
+}
+
+signed_transaction wallet_api::withdraw_GPOS_vesting_balance(
+ string account_name,
+ string amount,
+ string asset_symbol,
+ bool broadcast)
+{
+ return my->withdraw_GPOS_vesting_balance( account_name, amount, asset_symbol, broadcast );
}
signed_transaction wallet_api::vote_for_committee_member(string voting_account,