Skip to content

Commit

Permalink
Merge pull request IntersectMBO#2852 from IntersectMBO/simplify_rewards
Browse files Browse the repository at this point in the history
fix: fix IndexError when getting address
  • Loading branch information
mkoura authored Dec 20, 2024
2 parents e161901 + 75c7b29 commit dc8b286
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions cardano_node_tests/utils/dbsync_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Functionality for interacting with db-sync."""

import functools
import itertools
import logging
import time
import typing as tp
Expand All @@ -26,42 +27,29 @@ def get_address_reward(
The `epoch_from` and `epoch_to` are epochs where the reward can be spent.
"""
rewards: list[dbsync_types.RewardEpochRecord] = []
rewards.extend(
dbsync_types.RewardEpochRecord(
amount=int(db_row.amount),
earned_epoch=db_row.earned_epoch,
spendable_epoch=db_row.spendable_epoch,
type=db_row.type,
pool_id=db_row.pool_id or "",
)
for db_row in dbsync_queries.query_address_reward(
rewards_out = itertools.chain(
dbsync_queries.query_address_reward(
address=address, epoch_from=epoch_from, epoch_to=epoch_to
)
)

reward_rest = list(
),
dbsync_queries.query_address_reward_rest(
address=address, epoch_from=epoch_from, epoch_to=epoch_to
)
),
)
rewards.extend(
rewards: list[dbsync_types.RewardEpochRecord] = [
dbsync_types.RewardEpochRecord(
amount=int(db_row.amount),
earned_epoch=db_row.earned_epoch,
spendable_epoch=db_row.spendable_epoch,
type=db_row.type,
pool_id=db_row.pool_id or "",
)
for db_row in reward_rest
)
for db_row in rewards_out
]
if not rewards:
return dbsync_types.RewardRecord(address=address, reward_sum=0, rewards=[])

reward_sum = functools.reduce(lambda x, y: x + y.amount, rewards, 0)
return dbsync_types.RewardRecord(
address=reward_rest[-1].address, reward_sum=reward_sum, rewards=rewards
)
return dbsync_types.RewardRecord(address=address, reward_sum=reward_sum, rewards=rewards)


def check_address_reward(
Expand Down

0 comments on commit dc8b286

Please sign in to comment.