Skip to content

Commit a0438d8

Browse files
committed
ticket_booth
1 parent f4c9404 commit a0438d8

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

packages/metagame/src/libs.cairo

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ use starknet::ContractAddress;
1313
/// # Arguments
1414
/// * `minigame_token_address` - The address of the minigame token contract
1515
/// * `game_address` - The address of the game contract to check
16-
pub fn assert_game_registered(
17-
game_address: ContractAddress,
18-
) {
16+
pub fn assert_game_registered(game_address: ContractAddress) {
1917
let minigame_dispatcher = IMinigameDispatcher { contract_address: game_address };
2018
let minigame_token_address = minigame_dispatcher.token_address();
21-
let minigame_token_dispatcher = IMinigameTokenDispatcher { contract_address: minigame_token_address };
19+
let minigame_token_dispatcher = IMinigameTokenDispatcher {
20+
contract_address: minigame_token_address,
21+
};
2222
let minigame_registry_address = minigame_token_dispatcher.game_registry_address();
2323
let minigame_registry_dispatcher = IMinigameRegistryDispatcher {
2424
contract_address: minigame_registry_address,
@@ -60,8 +60,8 @@ pub fn mint(
6060
soulbound: bool,
6161
) -> u64 {
6262
match game_address {
63-
// If the game address is provided, mint a token through the token contract the game supports (could include
64-
// its own game registry)
63+
// If the game address is provided, mint a token through the token contract the game
64+
// supports (could include its own game registry)
6565
Option::Some(game_address) => {
6666
let minigame_dispatcher = IMinigameDispatcher { contract_address: game_address };
6767
let minigame_token_address = minigame_dispatcher.token_address();
@@ -81,26 +81,28 @@ pub fn mint(
8181
renderer_address,
8282
to,
8383
soulbound,
84-
)
84+
)
8585
},
86-
// If no game address is provided, mint a token through the default token contract (blank game)
86+
// If no game address is provided, mint a token through the default token contract (blank
87+
// game)
8788
Option::None => {
8889
let minigame_token_dispatcher = IMinigameTokenDispatcher {
8990
contract_address: default_token_address,
9091
};
91-
minigame_token_dispatcher.mint(
92-
Option::None,
93-
player_name,
94-
settings_id,
95-
start,
96-
end,
97-
objective_ids,
98-
context,
99-
client_url,
100-
renderer_address,
101-
to,
102-
soulbound,
103-
)
104-
}
92+
minigame_token_dispatcher
93+
.mint(
94+
Option::None,
95+
player_name,
96+
settings_id,
97+
start,
98+
end,
99+
objective_ids,
100+
context,
101+
client_url,
102+
renderer_address,
103+
to,
104+
soulbound,
105+
)
106+
},
105107
}
106108
}

packages/metagame/src/ticket_booth.cairo

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub mod TicketBoothComponent {
5959
pub struct GoldenPass {
6060
pub cooldown: u64, // Duration after which the pass can be used again, must be greater than 0
6161
pub game_expiration: GameExpiration, // Duration after which games minted with this pass expires
62-
pub pass_expiration: u64, // timestamp when the pass expires (becoming unusable), 0 means no expiration
62+
pub pass_expiration: u64 // timestamp when the pass expires (becoming unusable), 0 means no expiration
6363
}
6464

6565
#[event]
@@ -149,7 +149,7 @@ pub mod TicketBoothComponent {
149149
},
150150
Result::Err(_) => {
151151
// burn_from failed, fall back to zero address transfer
152-
let zero_address: ContractAddress = 0.try_into().unwrap();
152+
let zero_address: ContractAddress = starknet::contract_address_const::<0>();
153153
let _ = payment_token.transfer_from(caller, zero_address, cost.into());
154154
},
155155
}
@@ -192,7 +192,8 @@ pub mod TicketBoothComponent {
192192
to: ContractAddress,
193193
soulbound: bool,
194194
) -> u64 {
195-
assert!(get_block_timestamp() >= self.opening_time.read(), "Game not open yet");
195+
let current_time = get_block_timestamp();
196+
assert!(current_time >= self.opening_time.read(), "Game not open yet");
196197

197198
let caller = get_caller_address();
198199

@@ -201,7 +202,6 @@ pub mod TicketBoothComponent {
201202
assert!(golden_pass_config.cooldown > 0_u64, "Golden pass not configured");
202203

203204
// Check if the pass is expired
204-
let current_time = get_block_timestamp();
205205
if golden_pass_config.pass_expiration > 0_u64 {
206206
assert!(current_time < golden_pass_config.pass_expiration, "Golden pass expired");
207207
}
@@ -217,7 +217,6 @@ pub mod TicketBoothComponent {
217217
let last_used = self
218218
.golden_pass_last_used
219219
.read((golden_pass_address, golden_pass_token_id));
220-
let current_time = get_block_timestamp();
221220

222221
assert!(
223222
current_time >= last_used + golden_pass_config.cooldown, "Golden pass on cooldown",
@@ -280,7 +279,7 @@ pub mod TicketBoothComponent {
280279
) -> u64 {
281280
self.golden_pass_last_used.read((golden_pass_address, token_id))
282281
}
283-
282+
284283
fn ticket_receiver_address(self: @ComponentState<TContractState>) -> ContractAddress {
285284
self.ticket_receiver_address.read()
286285
}
@@ -350,7 +349,7 @@ pub mod TicketBoothComponent {
350349
self.cost_to_play.write(cost_to_play);
351350
match game_address {
352351
Option::Some(addr) => self.game_address.write(addr),
353-
Option::None => self.game_address.write(0.try_into().unwrap()),
352+
Option::None => self.game_address.write(starknet::contract_address_const::<0>()),
354353
};
355354
self.settings_id.write(settings_id);
356355
self.start_time.write(start_time);
@@ -369,7 +368,10 @@ pub mod TicketBoothComponent {
369368
break;
370369
}
371370
let (address, config) = passes.at(i);
372-
assert!(*config.cooldown > 0_u64, "Golden pass cooldown must be greater than zero");
371+
assert!(
372+
*config.cooldown > 0_u64,
373+
"Golden pass cooldown must be greater than zero",
374+
);
373375
self.golden_passes.write(*address, config.clone());
374376
i += 1;
375377
};

0 commit comments

Comments
 (0)