-
Notifications
You must be signed in to change notification settings - Fork 0
/
modified_vesting_lock_validator
52 lines (46 loc) · 1.34 KB
/
modified_vesting_lock_validator
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
43
44
45
46
47
48
49
50
51
52
use aiken/hash.{Blake2b_224, Hash}
use aiken/transaction/credential.{VerificationKey}
type Datum {
/// POSIX time in second, e.g. 1672843961000
lock_until: POSIXTime,
/// POSIX time in second, e.g. 1672843961000 + 2 days
return_time: POSIXTime,
/// Owner's credentials
owner: VerificationKeyHash,
/// Beneficiary's credentials
beneficiary: VerificationKeyHash,
}
type VerificationKeyHash =
Hash<Blake2b_224, VerificationKey>
type POSIXTime =
Int
validator {
fn vesting(datum: Datum, _redeemer: Void, ctx: ScriptContext) {
// spending eUTxO
when ctx.purpose is {
Spend(_) ->
or([
must_be_signed_by(ctx.transaction, datum.owner),
and([
must_be_signed_by(ctx.transaction, datum.beneficiary),
must_start_after(ctx.transaction.validity_range, datum.lock_until),
]),
and([
must_be_signed_by(ctx.transaction, datum.owner),
must_start_after(ctx.transaction.validity_range, datum.return_time),
])
])
_ ->
False
}
}
}
fn must_be_signed_by(transaction: Transaction, vk: VerificationKeyHash) {
list.has(transaction.extra_signatories, vk)
}
fn must_start_after(range: ValidityRange, lower_bound: POSIXTime) {
when range.lower_bound.bound_type is {
Finite(now) -> now >= lower_bound
_ -> False
}
}