-
Notifications
You must be signed in to change notification settings - Fork 80
/
ex07.cairo
72 lines (61 loc) · 1.97 KB
/
ex07.cairo
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
60
61
62
63
64
65
66
67
68
69
######### Ex 07
## Understanding functions to compare values
# In this exercice, you need to:
# - Use this contract's claim_points() function
# - Your points are credited by the contract
######### References
# Documentation is still being written. You can find answers in this file
# https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/math.cairo
%lang starknet
%builtins pedersen range_check
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.starknet.common.syscalls import (get_caller_address)
from starkware.cairo.common.math import (
assert_not_zero,
assert_not_equal,
assert_nn,
assert_le,
assert_lt,
assert_in_range
)
from contracts.utils.ex00_base import (
tderc20_address,
has_validated_exercise,
distribute_points,
validate_exercise,
ex_initializer
)
#
# Constructor
#
@constructor
func constructor{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
_tderc20_address: felt,
_players_registry: felt,
_workshop_id: felt,
_exercise_id: felt
):
ex_initializer(_tderc20_address, _players_registry, _workshop_id, _exercise_id)
return ()
end
#
# External functions
# Calling this function will simply credit 2 points to the address specified in parameter
#
@external
func claim_points{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(value_a: felt, value_b: felt):
# Reading caller address
let (sender_address) = get_caller_address()
# Checking that the passed values are correct
assert_not_zero(value_a)
assert_nn(value_b)
assert_not_equal(value_a, value_b)
assert_le(value_a, 75)
assert_in_range(value_a, 40, 70)
assert_lt(value_b, 1)
# Checking if the user has validated the exercice before
validate_exercise(sender_address)
# Sending points to the address specified as parameter
distribute_points(sender_address, 2)
return ()
end