Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
habanoz committed Oct 16, 2019
1 parent 77757c7 commit b13106b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
19 changes: 11 additions & 8 deletions src/rpc/lrpc_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_rewards_for_cycle_map(self, cycle):

return reward_model

def __get_unfrozen_rewards(self, level_of_last_block_in_unfreeze_cycle):
def __get_unfrozen_rewards(self, level_of_last_block_in_unfreeze_cycle, cycle):
request_metadata = self.COMM_BLOCK.format(self.node_url, level_of_last_block_in_unfreeze_cycle) + '/metadata'
metadata = self.do_rpc_request(request_metadata)
balance_updates = metadata["balance_updates"]
Expand All @@ -93,14 +93,17 @@ def __get_unfrozen_rewards(self, level_of_last_block_in_unfreeze_cycle):
balance_update = balance_updates[i]
if balance_update["kind"] == "freezer":
if balance_update["delegate"] == self.baking_address:
if balance_update["category"] == "rewards":
unfrozen_rewards = -int(balance_update["change"])
logger.debug("[__get_unfrozen_rewards] Found balance update for reward {}".format(balance_update))
elif balance_update["category"] == "fees":
unfrozen_fees = -int(balance_update["change"])
logger.debug("[__get_unfrozen_rewards] Found balance update for fee {}".format(balance_update))
if int(balance_update["cycle"]) != cycle or int(balance_update["change"])>0:
if balance_update["category"] == "rewards":
unfrozen_rewards = -int(balance_update["change"])
logger.debug("[__get_unfrozen_rewards] Found balance update for reward {}".format(balance_update))
elif balance_update["category"] == "fees":
unfrozen_fees = -int(balance_update["change"])
logger.debug("[__get_unfrozen_rewards] Found balance update for fee {}".format(balance_update))
else:
logger.debug("[__get_unfrozen_rewards] Found balance update, not including: {}".format(balance_update))
else:
logger.debug("[__get_unfrozen_rewards] Found balance update, not including: {}".format(balance_update))
logger.debug("[__get_unfrozen_rewards] Found balance update, cycle does not match or change is non-zero, not including: {}".format(balance_update))

return unfrozen_fees + unfrozen_rewards

Expand Down
21 changes: 12 additions & 9 deletions src/rpc/prpc_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_rewards_for_cycle_map(self, cycle):
logger.debug("Cycle {}, preserved cycles {}, blocks per cycle {}, last_block_cycle {}".format(cycle, self.preserved_cycles, self.blocks_per_cycle, level_of_last_block_in_unfreeze_cycle))

if current_level - level_of_last_block_in_unfreeze_cycle >= 0:
unfrozen_rewards = self.__get_unfrozen_rewards(level_of_last_block_in_unfreeze_cycle)
unfrozen_rewards = self.__get_unfrozen_rewards(level_of_last_block_in_unfreeze_cycle, cycle)
reward_data["total_rewards"] = unfrozen_rewards

else:
Expand All @@ -82,7 +82,7 @@ def get_rewards_for_cycle_map(self, cycle):

return reward_model

def __get_unfrozen_rewards(self, level_of_last_block_in_unfreeze_cycle):
def __get_unfrozen_rewards(self, level_of_last_block_in_unfreeze_cycle, cycle):
request_metadata = self.COMM_BLOCK.format(self.node_url, level_of_last_block_in_unfreeze_cycle) + '/metadata'
metadata = self.do_rpc_request(request_metadata)
balance_updates = metadata["balance_updates"]
Expand All @@ -92,14 +92,17 @@ def __get_unfrozen_rewards(self, level_of_last_block_in_unfreeze_cycle):
balance_update = balance_updates[i]
if balance_update["kind"] == "freezer":
if balance_update["delegate"] == self.baking_address:
if balance_update["category"] == "rewards":
unfrozen_rewards = -int(balance_update["change"])
logger.debug("[__get_unfrozen_rewards] Found balance update for reward {}".format(balance_update))
elif balance_update["category"] == "fees":
unfrozen_fees = -int(balance_update["change"])
logger.debug("[__get_unfrozen_rewards] Found balance update for fee {}".format(balance_update))
if int(balance_update["cycle"]) != cycle or int(balance_update["change"])>0:
if balance_update["category"] == "rewards":
unfrozen_rewards = -int(balance_update["change"])
logger.debug("[__get_unfrozen_rewards] Found balance update for reward {}".format(balance_update))
elif balance_update["category"] == "fees":
unfrozen_fees = -int(balance_update["change"])
logger.debug("[__get_unfrozen_rewards] Found balance update for fee {}".format(balance_update))
else:
logger.debug("[__get_unfrozen_rewards] Found balance update, not including: {}".format(balance_update))
else:
logger.debug("[__get_unfrozen_rewards] Found balance update, not including: {}".format(balance_update))
logger.debug("[__get_unfrozen_rewards] Found balance update, cycle does not match or change is non-zero, not including: {}".format(balance_update))

return unfrozen_fees + unfrozen_rewards

Expand Down

0 comments on commit b13106b

Please sign in to comment.