Skip to content

Commit

Permalink
refactor: guard against unexpected format
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantios committed Nov 2, 2023
1 parent 175d840 commit 4bc6063
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,13 @@ def _build_claim_data(self) -> WaitableConditionType:
if not self.redeeming_progress.claim_finished:
yield from self.wait_for_condition_with_sleep(self.get_claim_params)

claim_params = self.redeeming_progress.claim_params
if claim_params is None:
self.context.logger.error(
f"Cannot parse incorrectly formatted realitio `LogNewAnswer` events: {self.redeeming_progress.answered}"
)
return False

result = yield from self._realitio_interact(
contract_callable="build_claim_winnings",
data_key="data",
Expand Down
33 changes: 18 additions & 15 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,29 @@ def claim_finished(self) -> bool:
return self.claim_started and self.claim_from_block == self.claim_to_block

@property
def claim_params(self) -> ClaimParamsType:
def claim_params(self) -> Optional[ClaimParamsType]:
"""The claim parameters, prepared for the `claimWinnings` call."""
history_hashes = []
addresses = []
bonds = []
answers = []
for i, answer in enumerate(reversed(self.answered)):
# history_hashes second-last-to-first, the hash of each history entry, calculated as described here:
# https://realitio.github.io/docs/html/contract_explanation.html#answer-history-entries.
if i == len(self.answered) - 1:
history_hashes.append(ZERO_BYTES)
else:
history_hashes.append(self.answered[i + 1]["args"]["history_hash"])

# last-to-first, the address of each answerer or commitment sender
addresses.append(answer["args"]["user"])
# last-to-first, the bond supplied with each answer or commitment
bonds.append(answer["args"]["bond"])
# last-to-first, each answer supplied, or commitment ID if the answer was supplied with commit->reveal
answers.append(answer["args"]["answer"])
try:
for i, answer in enumerate(reversed(self.answered)):
# history_hashes second-last-to-first, the hash of each history entry, calculated as described here:
# https://realitio.github.io/docs/html/contract_explanation.html#answer-history-entries.
if i == len(self.answered) - 1:
history_hashes.append(ZERO_BYTES)
else:
history_hashes.append(self.answered[i + 1]["args"]["history_hash"])

# last-to-first, the address of each answerer or commitment sender
addresses.append(answer["args"]["user"])
# last-to-first, the bond supplied with each answer or commitment
bonds.append(answer["args"]["bond"])
# last-to-first, each answer supplied, or commitment ID if the answer was supplied with commit->reveal
answers.append(answer["args"]["answer"])
except KeyError:
return None

return history_hashes, addresses, bonds, answers

Expand Down

0 comments on commit 4bc6063

Please sign in to comment.