-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathDivineEclipseElements.cairo
executable file
·79 lines (66 loc) · 2.22 KB
/
DivineEclipseElements.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
70
71
72
73
74
75
76
77
78
79
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.starknet.common.syscalls import get_caller_address
from contracts.desiege.utils.interfaces import IModuleController
@storage_var
func controller_address() -> (address: felt) {
}
// Stores whether a (L1) address has minted
// for a given game idx
@storage_var
func has_minted(l1_address: felt, game_idx: felt) -> (has_minted: felt) {
}
// token IDs vary each game so token_id is only param required
@storage_var
func total_minted(token_id: felt) -> (total: felt) {
}
@constructor
func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
address_of_controller: felt
) {
controller_address.write(address_of_controller);
return ();
}
@view
func get_has_minted{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
l1_address: felt, game_idx: felt
) -> (result: felt) {
let (minted) = has_minted.read(l1_address, game_idx);
return (result=minted);
}
@external
func set_has_minted{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
l1_address: felt, game_idx: felt, minted_bool: felt
) {
only_approved();
has_minted.write(l1_address, game_idx, minted_bool);
return ();
}
@view
func get_total_minted{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
token_idx: felt
) -> (total: felt) {
let (total) = total_minted.read(token_idx);
return (total,);
}
@external
func set_total_minted{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
token_idx: felt, total: felt
) {
only_approved();
total_minted.write(token_idx, total);
return ();
}
// Checks write-permission of the calling contract.
func only_approved{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
// Get the address of the module trying to write to this contract.
let (caller) = get_caller_address();
let (controller) = controller_address.read();
// Pass this address on to the ModuleController.
// "Does this address have write-authority here?"
// Will revert the transaction if not.
IModuleController.has_write_access(
contract_address=controller, address_attempting_to_write=caller
);
return ();
}