Skip to content

Commit

Permalink
fix: dont garbage collect calldata
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Dec 19, 2023
1 parent 8f4185a commit aea76c0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
33 changes: 29 additions & 4 deletions example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,45 @@ int main()
return 1;
}

Call call = {
Call spawn = {
.to = "0x0152dcff993befafe5001975149d2c50bd9621da7cbaed74f68e7d5e54e65abc",
.selector = "spawn",
};

Result_bool resExecute = account_execute_raw(account, &call, 1);
if (resExecute.tag == Err_bool)
Call move = {
.to = "0x0152dcff993befafe5001975149d2c50bd9621da7cbaed74f68e7d5e54e65abc",
.selector = "move",
.calldata = {
.data = malloc(sizeof(FieldElement)),
.data_len = 1,
}
};

Result_FieldElement moveLeft = felt_from_hex_be("0x01");
if (moveLeft.tag == Err_FieldElement)
{
printf("Failed to execute call: %s\n", resExecute.err.message);
printf("Failed to create moveLeft: %s\n", moveLeft.err.message);
return 1;
}

move.calldata.data[0] = moveLeft.ok;

Result_bool resSpawn = account_execute_raw(account, &spawn, 1);
if (resSpawn.tag == Err_bool)
{
printf("Failed to execute call: %s\n", resSpawn.err.message);
return 1;
}

sleep(5);

Result_bool resMove = account_execute_raw(account, &move, 1);
if (resMove.tag == Err_bool)
{
printf("Failed to execute call: %s\n", resMove.err.message);
return 1;
}

// while (1)
// {

Expand Down
1 change: 1 addition & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl From<&Call> for starknet::accounts::Call {
let selector = unsafe { CStr::from_ptr(val.selector).to_string_lossy().to_string() };

let calldata: Vec<FieldElement> = (&val.calldata).into();
let calldata = std::mem::ManuallyDrop::new(calldata);
let calldata = calldata.iter().map(|c| (&c.clone()).into()).collect();

starknet::accounts::Call {
Expand Down

0 comments on commit aea76c0

Please sign in to comment.