-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path16-access-control.jsligo
43 lines (39 loc) · 1.43 KB
/
16-access-control.jsligo
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
/**
* Chapter 16 : Built-ins
* https://academy.ligolang.org/js/chapter-built-ins
*
* 1- Check that the originitor address is indeed our ship_address, or fail with "Access denied"
* 2- Check that the sent amount corresponds to the purchase_price, or fail with "Incorrect amount"
*
* cli test command
* - incorret source:
* `ligo run dry-run 16-access-control.jsligo --source "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" -e main 'unit' 'unit' --amount 10`
* - incorrect amount:
* `ligo run dry-run 16-access-control.jsligo --source "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" -e main 'unit' 'unit' --amount 1`
* - pass:
* `ligo run dry-run 16-access-control.jsligo --source "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" -e main 'unit' 'unit' --amount 10`
*/
type storage = unit;
type parameter =
| ["Purchase"];
type return_ = [list<operation>, storage];
const purchase = (store: storage): return_ => {
const ship_address: address = ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" as address);
const purchase_price: tez = 10 as tez;
// Type your solution below
if (Tezos.get_source() != ship_address) {
return failwith ("Access denied");
} else {
unit;
};
if (Tezos.get_amount() != purchase_price) {
return failwith ("Incorrect amount");
} else {
unit;
};
return [list([]), store];
};
const main = (action: parameter, store: storage): return_ =>
match(action, {
Purchase: () => purchase(store),
});