A implementation of calculating RC can also be found in beem.
rc.py: https://github.com/holgern/beem/blob/master/beem/rc.py
constants.py: https://github.com/holgern/beem/blob/master/beem/constants.py
def get_rc_cost(self, resource_count):
"""Returns the RC costs based on the resource_count"""
pools = self.get_resource_pool()
params = self.get_resource_params()
config = self.get_config()
dyn_param = self.get_dynamic_global_properties()
rc_regen = int(Amount(dyn_param["total_vesting_shares"], steem_instance=self)) / (STEEM_RC_REGEN_TIME / config["STEEM_BLOCK_INTERVAL"])
total_cost = 0
if rc_regen == 0:
return total_cost
for resource_type in resource_count:
curve_params = params[resource_type]["price_curve_params"]
current_pool = int(pools[resource_type]["pool"])
count = resource_count[resource_type]
count *= params[resource_type]["resource_dynamics_params"]["resource_unit"]
cost = self._compute_rc_cost(curve_params, current_pool, count, rc_regen)
total_cost += cost
return total_cost
def _compute_rc_cost(self, curve_params, current_pool, resource_count, rc_regen):
"""Helper function for computing the RC costs"""
num = int(rc_regen)
num *= int(curve_params['coeff_a'])
num = int(num) >> int(curve_params['shift'])
num += 1
num *= int(resource_count)
denom = int(curve_params['coeff_b'])
if int(current_pool) > 0:
denom += int(current_pool)
num_denom = num / denom
return int(num_denom) + 1
in steem.py: https://github.com/holgern/beem/blob/master/beem/steem.py
RE: Developer Guide: Resource Credit System