Skip to content

Commit

Permalink
Simplify method using key lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Apr 11, 2023
1 parent 3aa3f41 commit 137444d
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions opshin/prelude.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,10 @@ def resolve_datum(txout: TxOut, tx_info: TxInfo) -> BuiltinData:
attached_datum = txout.datum
if isinstance(attached_datum, SomeOutputDatumHash):
# TODO can we raise a KeyError here if not found?
@dataclass
class InvalidDatum(PlutusData):
CONSTR_ID = 42
a: int

invalid = InvalidDatum(1234321)
res = tx_info.data.get(attached_datum.datum_hash, invalid)
assert (
res != invalid
attached_datum.datum_hash in tx_info.data.keys()
), "The datum matching the given datum hash was not embedded into the transaction"
res = tx_info.data.get(attached_datum.datum_hash, Nothing())
elif isinstance(attached_datum, SomeOutputDatum):
res = attached_datum.datum
else:
Expand Down

0 comments on commit 137444d

Please sign in to comment.