Merge pull request #163 from peerplays-network/153/fix-add-on

Changes to have separate withdraw_vesting methods and single withdraw fee for multiple objects
This commit is contained in:
pbattu123 2019-10-06 16:39:07 -03:00 committed by GitHub
commit d5dffa64b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 19 deletions

View file

@ -46,6 +46,7 @@ class vesting_balance_withdraw_evaluator : public evaluator<vesting_balance_with
void_result do_evaluate( const vesting_balance_withdraw_operation& op );
void_result do_apply( const vesting_balance_withdraw_operation& op );
virtual operation_result start_evaluate(transaction_evaluation_state& eval_state, const operation& op, bool apply);
};
} } // graphene::chain

View file

@ -115,6 +115,29 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance
return vbo.id;
} FC_CAPTURE_AND_RETHROW( (op) ) }
operation_result vesting_balance_withdraw_evaluator::start_evaluate( transaction_evaluation_state& eval_state, const operation& op, bool apply )
{ try {
trx_state = &eval_state;
database& d = db();
const auto& oper = op.get<vesting_balance_withdraw_operation>();
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 );

View file

@ -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)

View file

@ -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<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>(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<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>(account_name);
if( !vbid )
{
//Changes done to retrive user account/witness account based on account name
fc::optional<account_id_type> acct_id = maybe_id<account_id_type>( witness_name );
fc::optional<account_id_type> acct_id = maybe_id<account_id_type>( 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<vesting_balance_id_type> 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,