Skip to content

Instantly share code, notes, and snippets.

@Th0rgal
Created November 9, 2022 21:45
Show Gist options
  • Save Th0rgal/9b46452c8a247e920d00df881b28c5fe to your computer and use it in GitHub Desktop.
Save Th0rgal/9b46452c8a247e920d00df881b28c5fe to your computer and use it in GitHub Desktop.
%lang starknet
from starkware.cairo.common.math import assert_nn
from starkware.cairo.common.cairo_builtins import HashBuiltin
struct Call {
to: felt,
selector: felt,
data_offset: felt,
data_len: felt,
}
@view
func iterate_over_calls{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
calls_len, calls: Call*, calldata_len: felt, calldata: felt*
) -> () {
if (calls_len == 0) {
return ();
}
iterate_over_calls(calls_len - 1, calls, calldata_len, calldata);
let last_call: Call = calls[calls_len - 1];
handle_one_call(
last_call.to, last_call.selector, last_call.data_len, calldata + last_call.data_offset
);
return ();
}
func handle_one_call{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
to, selector, calldata_len, calldata: felt*
) -> () {
%{
print("here you can call", ids.to, ids.selector, "with data:")
for i in range(ids.calldata_len):
print(str(i) + ")", memory[ids.calldata+i])
%}
return ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment