forked from OpenZeppelin/cairo-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.cairo
42 lines (35 loc) · 1.24 KB
/
library.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
# SPDX-License-Identifier: MIT
# OpenZeppelin Contracts for Cairo v0.2.1 (introspection/erc165/library.cairo)
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.math import assert_not_equal
from starkware.cairo.common.bool import TRUE
from openzeppelin.utils.constants.library import INVALID_ID, IERC165_ID
@storage_var
func ERC165_supported_interfaces(interface_id: felt) -> (is_supported: felt):
end
namespace ERC165:
func supports_interface{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
} (interface_id: felt) -> (success: felt):
if interface_id == IERC165_ID:
return (TRUE)
end
# Checks interface registry
let (is_supported) = ERC165_supported_interfaces.read(interface_id)
return (is_supported)
end
func register_interface{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
} (interface_id: felt):
with_attr error_message("ERC165: invalid interface id"):
assert_not_equal(interface_id, INVALID_ID)
end
ERC165_supported_interfaces.write(interface_id, TRUE)
return ()
end
end