-
Notifications
You must be signed in to change notification settings - Fork 2
/
contract.ts
59 lines (45 loc) · 1.8 KB
/
contract.ts
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
53
54
55
56
57
58
59
import { Address, bool, compile, data, Credential, pBool, pdelay, pfn, pmatch, PScriptContext, pStr, ptraceIfFalse, Script, ScriptType, plet, passert, perror, PMaybe, unit, punsafeConvertType } from "@harmoniclabs/plu-ts";
import VestingDatum from "./VestingDatum";
export const contract = pfn([
PScriptContext.type
], unit)
(( {redeemer, tx, purpose} ) => {
const maybeDatum = plet(
pmatch(purpose)
.onSpending(({ datum }) => datum)
._(_ => perror(PMaybe(data).type))
);
const datum = plet( punsafeConvertType( maybeDatum.unwrap, VestingDatum.type ) )
const signedByBeneficiary = tx.signatories.some( datum.beneficiary.eq )
// inlined
const deadlineReached = plet(
pmatch( tx.interval.from.bound )
.onPFinite(({ n: lowerInterval }) =>
datum.deadline.ltEq( lowerInterval )
)
._( _ => pBool( false ) )
)
return passert.$(
(ptraceIfFalse.$(pdelay(pStr("Error in signedByBenificiary"))).$(signedByBeneficiary))
.and( ptraceIfFalse.$(pdelay(pStr("deadline not reached or not specified"))).$( deadlineReached ) )
);
});
///////////////////////////////////////////////////////////////////
// ------------------------------------------------------------- //
// ------------------------- utilities ------------------------- //
// ------------------------------------------------------------- //
///////////////////////////////////////////////////////////////////
export const compiledContract = compile( contract );
export const script = new Script(
ScriptType.PlutusV3,
compiledContract
);
export const scriptMainnetAddr = new Address(
"mainnet",
Credential.script( script.hash )
);
export const scriptTestnetAddr = new Address(
"testnet",
Credential.script( script.hash )
);
export default contract;