-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaucet.py
More file actions
42 lines (37 loc) · 1.47 KB
/
faucet.py
File metadata and controls
42 lines (37 loc) · 1.47 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
from eopsin.prelude import *
LOVELACE = 11000000
PAY_HASH = b"\x28\x33\xc6\xe8\x69\x65\xfb\x87\x69\x48\xa2\xbc\x89\x62\x4d\xde\xd4\x7c\x9e\xb2\x4f\xe7\x33\x8b\xc2\x0e\x15\x43"
def has_paid(txouts: List[TxOut], payhash: PubKeyHash) -> bool:
res = False
for txo in txouts:
if txo.value.get(b"", {b"":0}).get(b"",0) == LOVELACE:
cred = txo.address.credential
if isinstance(cred, PubKeyCredential):
pkh = cred.pubkeyhash
if pkh == payhash:
res = True
assert res, "Incorrect Address/Amount Used"
return res
def own_spent_utxo(txins: List[TxInInfo], p: Spending) -> TxOut:
for txi in txins:
if txi.out_ref == p.tx_out_ref:
own_txout = txi.resolved
return own_txout
def contract_utxo_count(txins: List[TxInInfo], addr: Address) -> int:
count = 0
for txi in txins:
if txi.resolved.address == addr:
count += 1
assert count == 1, "Only 1 contract utxo allowed"
return count
def validator(datum: None, redeemer: None, context: ScriptContext) -> None:
purpose = context.purpose
allowspend = False
if isinstance(purpose, Spending):
own_utxo = own_spent_utxo(context.tx_info.inputs, purpose)
own_addr = own_utxo.address
count = contract_utxo_count(context.tx_info.inputs,own_addr)
paid = has_paid(context.tx_info.outputs,PAY_HASH)
if count == 1 and paid:
allowspend = True
assert allowspend