Skip to content

Commit

Permalink
Removed all debug prints from contract code (not tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 17, 2024
1 parent e6b2aba commit 8d31034
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 45 deletions.
16 changes: 0 additions & 16 deletions contracts/src/apps/paint/app.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ mod paint_actions {
/// * `world` - A reference to the world dispatcher.
/// * `default_params` - The default parameters including position and color.
fn interact(ref world: IWorldDispatcher, default_params: DefaultParameters) {
println!("interact");

let position = default_params.position;

// Load the Pixel
Expand All @@ -175,8 +173,6 @@ mod paint_actions {
/// * `world` - A reference to the world dispatcher.
/// * `default_params` - The default parameters including position and color.
fn put_color(ref world: IWorldDispatcher, default_params: DefaultParameters) {
println!("put_color");

// Load important variables
let core_actions = get_core_actions(world);
let position = default_params.position;
Expand Down Expand Up @@ -215,8 +211,6 @@ mod paint_actions {
action: Option::None, // Not using this feature for paint
},
);

println!("put_color DONE");
}

/// Updates a row of pixels with provided image data.
Expand All @@ -238,7 +232,6 @@ mod paint_actions {
// continue (x - offset) to the left

if image_data.is_empty() {
println!("image_data empty");
return;
}

Expand All @@ -251,7 +244,6 @@ mod paint_actions {
let mut pixel_index = 0;
let mut felt: u256 = (*image_data.at(felt_index)).into();
let mut stop = false;
println!("first felt: {}", felt);

while !stop {
// Each felt contains 7 pixels of 4 bytes each, so 224 bits. The leftmost 28 bits
Expand Down Expand Up @@ -302,29 +294,23 @@ mod paint_actions {
/// * `world` - A reference to the world dispatcher.
/// * `default_params` - The default parameters including position and color.
fn fade(ref world: IWorldDispatcher, default_params: DefaultParameters) {
println!("fade");

let core_actions = get_core_actions(world);
let position = default_params.position;
let player = core_actions.get_player_address(default_params.for_player);
let system = core_actions.get_system_address(default_params.for_system);
let pixel = get!(world, (position.x, position.y), Pixel);

println!("decode_color");

let (r, g, b, a) = decode_color(pixel.color);

// If the color is 0,0,0, fading is done.
if r == 0 && g == 0 && b == 0 {
println!("fading is done");
delete!(world, (pixel));
return;
}

// Fade the color
let FADE_STEP = 5;

println!("encode_color");
let new_color = encode_color(
subu8(r, FADE_STEP), subu8(g, FADE_STEP), subu8(b, FADE_STEP), a,
);
Expand Down Expand Up @@ -375,7 +361,6 @@ mod paint_actions {
0x89ce6748d77414b79f2312bb20f6e67d3aa4a9430933a0f461fedc92983084, // Selector for fade
calldata.span(), // The prepared calldata
);
println!("put_fading_color DONE");
}
}

Expand Down Expand Up @@ -419,7 +404,6 @@ mod paint_actions {
} else {
0
};
println!("{}", result);
result
}
}
11 changes: 0 additions & 11 deletions contracts/src/apps/snake/app.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ mod snake_actions {
fn interact(
ref world: IWorldDispatcher, default_params: DefaultParameters, direction: Direction,
) -> u32 {
println!("snake: interact");

let core_actions = get_core_actions(world);
let position = default_params.position;

Expand Down Expand Up @@ -373,8 +371,6 @@ mod snake_actions {
/// * `world` - A reference to the world dispatcher.
/// * `owner` - The contract address of the snake's owner.
fn move(ref world: IWorldDispatcher, owner: ContractAddress) {
println!("snake: move");

let core_actions = get_core_actions(world);

// Load the Snake
Expand All @@ -385,12 +381,10 @@ mod snake_actions {

// If the snake is dying, handle that
if snake.is_dying {
println!("snake shrinks due to dying");
snake.last_segment_id = remove_last_segment(world, core_actions, snake);
snake.length -= 1;

if snake.length == 0 {
println!("snake is dead: deleting");
let position = Position { x: first_segment.x, y: first_segment.y, };
core_actions.alert_player(position, snake.owner, 'Snake died here');
emit!(
Expand Down Expand Up @@ -433,7 +427,6 @@ mod snake_actions {
// MOVE, GROW, SHRINK, DIE
if next_pixel.owner == contract_address_const::<0>() {
// Snake just moves
println!("snake moves");
// Add a new segment on the next pixel and update the snake
snake
.first_segment_id =
Expand All @@ -442,11 +435,9 @@ mod snake_actions {
);
snake.last_segment_id = remove_last_segment(world, core_actions, snake);
} else if !has_write_access {
println!("snake will die");
// Snake hit a pixel that is not allowing anything: DIE
snake.is_dying = true;
} else if next_pixel.owner == snake.owner {
println!("snake grows");
// Next pixel is owned by snake owner: GROW

// Add a new segment
Expand All @@ -465,7 +456,6 @@ mod snake_actions {
}
// We leave the tail as is
} else {
println!("snake shrinks");
// Next pixel is not owned but can be used temporarily
// SHRINK, though
if snake.length == 1 {
Expand All @@ -482,7 +472,6 @@ mod snake_actions {
}
}
} else {
println!("snake will die");
// Snake hit a pixel that is not allowing anything: DIE
snake.is_dying = true;
}
Expand Down
19 changes: 1 addition & 18 deletions contracts/src/core/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ pub mod actions {
let allowed_app = get!(world, app_key, (AppName));
let allowed_app = allowed_app.system;

println!("appkey: {:?}", app_key);
println!("caller_address: {:?}", caller_address);
println!("allowed_app: {:?}", allowed_app);

set!(world, Permissions { allowing_app: caller_address, allowed_app, permission });
}

Expand All @@ -277,8 +273,6 @@ pub mod actions {
selector: felt252,
calldata: Span<felt252>,
) {
println!("schedule_queue");

// TODO: Review security

// hash the call and store the hash for verification
Expand All @@ -296,7 +290,6 @@ pub mod actions {
QueueScheduled { id, timestamp, called_system, selector, calldata: calldata }
))
);
println!("schedule_queue DONE");
}

/// Processes a scheduled queue item.
Expand All @@ -321,8 +314,6 @@ pub mod actions {
selector: felt252,
calldata: Span<felt252>,
) {
println!("process_queue");

// A quick check on the timestamp so we know it's not too early for this one
assert!(timestamp <= starknet::get_block_timestamp(), "timestamp still in the future");

Expand All @@ -342,7 +333,6 @@ pub mod actions {

// Tell the offchain schedulers that this one is done
emit!(world, (Event::QueueProcessed(QueueProcessed { id })));
println!("process_queue DONE");
}

/// Checks if a player or system has write access to a pixel.
Expand Down Expand Up @@ -442,16 +432,13 @@ pub mod actions {
for_system: ContractAddress,
pixel_update: PixelUpdate,
) {
println!("update_pixel");

let mut pixel = get!(world, (pixel_update.x, pixel_update.y), (Pixel));

assert!(
self.has_write_access(for_player, for_system, pixel, pixel_update), "No access!"
);

let old_pixel_app = pixel.app;
println!("{:?}", old_pixel_app);

if old_pixel_app != contract_address_const::<0>() {
let interoperable_app = IInteroperabilityDispatcher {
Expand Down Expand Up @@ -503,8 +490,6 @@ pub mod actions {
let app_caller = get!(world, for_system, (App));
interoperable_app.on_post_update(pixel_update, app_caller, for_player);
}

println!("update_pixel DONE");
}

/// Retrieves the player address.
Expand All @@ -519,13 +504,11 @@ pub mod actions {
/// * `ContractAddress` - The player address.
fn get_player_address(for_player: ContractAddress) -> ContractAddress {
if for_player == contract_address_const::<0>() {
println!("get_player_address.zero");
let result = get_tx_info().unbox().account_contract_address;
println!("{:?}", result);

// Return the caller account from the transaction (the end user)
return result;
} else {
println!("get_player_address.nonzero");
// TODO: Check if getter is a system or the core actions contract

// Return the `for_player`
Expand Down

0 comments on commit 8d31034

Please sign in to comment.