-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathhomework1.py
29 lines (24 loc) · 1.12 KB
/
homework1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Prompt:
# 1- Figure out what this (already finished) validator does by using all the tools at your disposal.
# 2- Write the off-chain code necessary to cover all possible interactions with the validator using
# the off-chain tool of your choosing.
# HINT: If you get stuck, take a look at Week03's lecture
from opshin.ledger.interval import *
@dataclass()
class MisteryDatum(PlutusData):
beneficiary1: PubKeyHash
beneficiary2: PubKeyHash
deadline: POSIXTime
def validator(datum: MisteryDatum, redeemer: None, context: ScriptContext) -> None:
valid_range = context.tx_info.valid_range
signed1 = datum.beneficiary1 in context.tx_info.signatories
deadline1 = contains(make_to(datum.deadline), valid_range)
condition1 = signed1 and deadline1
if not condition1:
print("Benificiary1 did not sign or to late")
signed2 = datum.beneficiary2 in context.tx_info.signatories
deadline2 = contains(make_from(datum.deadline + 1), valid_range)
condition2 = signed2 and deadline2
if not condition2:
print("Benificiary2 did not sign or is to early")
assert condition1 or condition2