Update how fees are paid
- price per kb for splitters (based on ram usage and number of parties) - pay payout fee when threshold is reached
This commit is contained in:
parent
c6b848ef18
commit
8b8d35fad1
2 changed files with 48 additions and 7 deletions
|
|
@ -35,8 +35,10 @@ namespace graphene { namespace chain {
|
||||||
|
|
||||||
struct splitter_create_operation : public base_operation
|
struct splitter_create_operation : public base_operation
|
||||||
{
|
{
|
||||||
/// TODO: charge fee based upon size
|
struct fee_parameters_type {
|
||||||
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION;
|
||||||
|
uint32_t price_per_kbyte = GRAPHENE_BLOCKCHAIN_PRECISION;
|
||||||
|
};
|
||||||
|
|
||||||
asset fee;
|
asset fee;
|
||||||
account_id_type payer;
|
account_id_type payer;
|
||||||
|
|
@ -59,12 +61,16 @@ namespace graphene { namespace chain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
account_id_type fee_payer()const { return payer; }
|
account_id_type fee_payer()const { return payer; }
|
||||||
|
share_type calculate_fee(const fee_parameters_type& k )const
|
||||||
|
{ return calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte ) + k.fee; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct splitter_update_operation : public base_operation
|
struct splitter_update_operation : public base_operation
|
||||||
{
|
{
|
||||||
/// TODO: charge fee based upon size
|
struct fee_parameters_type {
|
||||||
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION;
|
||||||
|
uint32_t price_per_kbyte = GRAPHENE_BLOCKCHAIN_PRECISION;
|
||||||
|
};
|
||||||
|
|
||||||
asset fee;
|
asset fee;
|
||||||
splitter_id_type splitter_id;
|
splitter_id_type splitter_id;
|
||||||
|
|
@ -85,6 +91,8 @@ namespace graphene { namespace chain {
|
||||||
}
|
}
|
||||||
|
|
||||||
account_id_type fee_payer()const { return owner; }
|
account_id_type fee_payer()const { return owner; }
|
||||||
|
share_type calculate_fee(const fee_parameters_type& k )const
|
||||||
|
{ return calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte ) + k.fee; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct splitter_pay_operation : public base_operation
|
struct splitter_pay_operation : public base_operation
|
||||||
|
|
@ -139,8 +147,8 @@ FC_REFLECT( graphene::chain::splitter_update_operation, (fee)(owner)(new_owner)(
|
||||||
FC_REFLECT( graphene::chain::splitter_pay_operation, (fee)(splitter_id)(paying_account)(payment) )
|
FC_REFLECT( graphene::chain::splitter_pay_operation, (fee)(splitter_id)(paying_account)(payment) )
|
||||||
FC_REFLECT( graphene::chain::splitter_payout_operation, (fee)(splitter_id)(owner) )
|
FC_REFLECT( graphene::chain::splitter_payout_operation, (fee)(splitter_id)(owner) )
|
||||||
FC_REFLECT( graphene::chain::splitter_delete_operation, (fee)(splitter_id)(owner) )
|
FC_REFLECT( graphene::chain::splitter_delete_operation, (fee)(splitter_id)(owner) )
|
||||||
FC_REFLECT( graphene::chain::splitter_create_operation::fee_parameters_type, (fee) );
|
FC_REFLECT( graphene::chain::splitter_create_operation::fee_parameters_type, (fee)(price_per_kbyte) );
|
||||||
FC_REFLECT( graphene::chain::splitter_update_operation::fee_parameters_type, (fee) );
|
FC_REFLECT( graphene::chain::splitter_update_operation::fee_parameters_type, (fee)(price_per_kbyte) );
|
||||||
FC_REFLECT( graphene::chain::splitter_pay_operation::fee_parameters_type, (fee) );
|
FC_REFLECT( graphene::chain::splitter_pay_operation::fee_parameters_type, (fee) );
|
||||||
FC_REFLECT( graphene::chain::splitter_payout_operation::fee_parameters_type, (fee) );
|
FC_REFLECT( graphene::chain::splitter_payout_operation::fee_parameters_type, (fee) );
|
||||||
FC_REFLECT( graphene::chain::splitter_delete_operation::fee_parameters_type, (fee) );
|
FC_REFLECT( graphene::chain::splitter_delete_operation::fee_parameters_type, (fee) );
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,41 @@ namespace graphene { namespace chain {
|
||||||
db.apply_order(new_order_object);
|
db.apply_order(new_order_object);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
void payout( database& db )const
|
void payout( database& db, bool pay_fee = true )const
|
||||||
{
|
{
|
||||||
|
/** this happens when the threshold is used as the trigger, but not when the payout operation is used */
|
||||||
|
if( pay_fee )
|
||||||
|
{
|
||||||
|
const auto& fee_config = db.get_global_properties().parameters.current_fees->get<splitter_payout_operation>();
|
||||||
|
asset fee_in_aobj_units = asset(fee_config.fee);
|
||||||
|
const asset_object& aobj = min_payment.asset_id(db);
|
||||||
|
const asset_dynamic_data_object& aobj_dyn = aobj.dynamic_asset_data_id(db);
|
||||||
|
if( aobj.id != asset_id_type() )
|
||||||
|
{
|
||||||
|
fee_in_aobj_units = asset(fee_config.fee) * aobj.options.core_exchange_rate;
|
||||||
|
/// not enough in fee pool to cover
|
||||||
|
if( aobj_dyn.fee_pool < fee_config.fee ) return;
|
||||||
|
}
|
||||||
|
/// not enough to cover payout fee, so don't payout.
|
||||||
|
if( fee_in_aobj_units > balance ) return;
|
||||||
|
|
||||||
|
|
||||||
|
db.modify( *this, [&]( splitter_object& obj ){ obj.balance-= fee_in_aobj_units; } );
|
||||||
|
|
||||||
|
if( aobj.id != asset_id_type() )
|
||||||
|
{
|
||||||
|
db.modify( aobj_dyn, [&]( asset_dynamic_data_object& obj ){
|
||||||
|
obj.accumulated_fees += fee_in_aobj_units.amount;
|
||||||
|
obj.fee_pool -= fee_config.fee;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
db.modify( aobj_dyn, [&]( asset_dynamic_data_object& obj ){
|
||||||
|
obj.current_supply -= fee_config.fee;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t total_weight = 0;
|
uint64_t total_weight = 0;
|
||||||
for( auto& t : targets ) total_weight += t.weight;
|
for( auto& t : targets ) total_weight += t.weight;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue