forked from starknet-edu/starknet-accounts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignature_3.cairo
82 lines (70 loc) · 1.88 KB
/
signature_3.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
80
81
82
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.starknet.common.syscalls import call_contract
from starkware.cairo.common.signature import verify_ecdsa_signature
from starkware.cairo.common.alloc import alloc
####################
# STORAGE VARIABLES
####################
@storage_var
func public_key() -> (res : felt):
end
#
# ACTION_ITEM 1: implement '@storage_var' account_nonce()
#
@storage_var
#
# <CODE>
#
####################
# CONSTRUCTOR
####################
@constructor
func constructor{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(pub_key : felt):
public_key.write(pub_key)
return ()
end
####################
# GETTERS
####################
#
# MISSION 1
#
@view
func get_nonce{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (res : felt):
let (res) = account_nonce.read()
return (res)
end
#
# MISSION 2
#
@view
func get_signer{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (
res : felt
):
let (res) = public_key.read()
return (res)
end
####################
# EXTERNAL FUNCTIONS
####################
@external
func __execute__{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
contract_address : felt, selector : felt, calldata_len : felt, calldata : felt*
) -> (retdata_len : felt, retdata : felt*):
let (_current_nonce) = account_nonce.read()
assert _current_nonce = calldata[0]
#
# ACTION ITEM 2: increment `account_nonce` for each transaction signature
#
#
# <CODE>
#
let (vec : felt*) = alloc()
assert [vec] = _current_nonce + 1
assert [vec + 1] = calldata[1]
let (retdata_len : felt, retdata : felt*) = call_contract(
contract_address=contract_address, function_selector=selector, calldata_size=2, calldata=vec
)
return (retdata_len=retdata_len, retdata=retdata)
end