Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Jan 14, 2025
1 parent 39fdb49 commit 362421a
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 54 deletions.
9 changes: 4 additions & 5 deletions src/channel_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,10 @@ impl ChannelHandler {
&cached.at_stake_amount,
);

let spend_transaction = cached.live_game.get_transaction_for_move(
env.allocator,
&game_coin,
false,
)?;
let spend_transaction =
cached
.live_game
.get_transaction_for_move(env.allocator, &game_coin, false)?;

Ok(Some(DispositionResult {
disposition: CoinSpentDisposition::Accept(CoinSpentAccept {
Expand Down
9 changes: 6 additions & 3 deletions src/channel_handler/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,9 +946,12 @@ impl LiveGame {
coin: Option<&CoinString>,
) -> Result<TheirTurnMoveResult, Error> {
assert!(!self.referee_maker.is_my_turn());
let their_move_result =
self.referee_maker
.their_turn_move_off_chain(allocator, game_move, state_number, coin)?;
let their_move_result = self.referee_maker.their_turn_move_off_chain(
allocator,
game_move,
state_number,
coin,
)?;
if let Some(ph) = &their_move_result.puzzle_hash_for_unroll {
self.last_referee_puzzle_hash = ph.clone();
}
Expand Down
3 changes: 2 additions & 1 deletion src/peer_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ impl ToLocalUI for SynchronousGameCradleState {
}
fn game_cancelled(&mut self, id: &GameID) -> Result<(), Error> {
// XXX cancelled list
self.game_finished.push_back((id.clone(), Amount::default()));
self.game_finished
.push_back((id.clone(), Amount::default()));
Ok(())
}
fn shutdown_complete(&mut self, reward_coin_string: Option<&CoinString>) -> Result<(), Error> {
Expand Down
7 changes: 4 additions & 3 deletions src/potato_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,9 +1769,10 @@ impl<G: ToLocalUI + BootstrapTowardWallet + WalletSpendInterface + PacketSender,
}

if !matches!(self.handshake_state, HandshakeState::Finished(_)) {
return Err(Error::StrErr(
format!("shut_down without finishing handshake {:?}", self.handshake_state)
));
return Err(Error::StrErr(format!(
"shut_down without finishing handshake {:?}",
self.handshake_state
)));
}

self.do_game_action(penv, GameAction::Shutdown(conditions))
Expand Down
32 changes: 22 additions & 10 deletions src/potato_handler/on_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ impl PotatoHandlerImpl for OnChainPotatoHandler {
// A game coin was spent and we have the puzzle and solution.
let (env, system_interface) = penv.env();
let conditions = CoinCondition::from_puzzle_and_solution(env.allocator, puzzle, solution)?;
let result = self.player_ch
.game_coin_spent(env, &old_definition.game_id, coin_id, &conditions);
let result =
self.player_ch
.game_coin_spent(env, &old_definition.game_id, coin_id, &conditions);
let their_turn_result = if let Ok(result) = result {
result
} else {
Expand Down Expand Up @@ -212,12 +213,18 @@ impl PotatoHandlerImpl for OnChainPotatoHandler {
debug!("{initial_potato} slash {outcome:?}");
self.have_potato = PotatoState::Present;
// XXX amount
let amount =
if let SlashOutcome::Reward { my_reward_coin_string, .. } = outcome.borrow() {
my_reward_coin_string.to_parts().map(|(_, _, amt)| amt.clone()).unwrap_or_else(|| Amount::default())
} else {
Amount::default()
};
let amount = if let SlashOutcome::Reward {
my_reward_coin_string,
..
} = outcome.borrow()
{
my_reward_coin_string
.to_parts()
.map(|(_, _, amt)| amt.clone())
.unwrap_or_else(|| Amount::default())
} else {
Amount::default()
};
debug!("{initial_potato} setting game finished");
system_interface.game_finished(&old_definition.game_id, amount)?;

Expand Down Expand Up @@ -364,7 +371,9 @@ impl PotatoHandlerImpl for OnChainPotatoHandler {
let initial_potato = self.player_ch.is_initial_potato();
let my_turn = self.player_ch.game_is_my_turn(&game_id);
if my_turn != Some(true) {
debug!("{initial_potato} trying to do game action when not my turn {readable_move:?}");
debug!(
"{initial_potato} trying to do game action when not my turn {readable_move:?}"
);
self.game_action_queue.push_front(GameAction::Move(
game_id,
readable_move,
Expand Down Expand Up @@ -445,7 +454,10 @@ impl PotatoHandlerImpl for OnChainPotatoHandler {
if let Some((current, _game)) = self.game_map.iter().find(|g| g.1.game_id == *game_id) {
Ok(current.clone())
} else {
Err(Error::StrErr(format!("no matching game in {:?}", self.game_map)))
Err(Error::StrErr(format!(
"no matching game in {:?}",
self.game_map
)))
}
};

Expand Down
52 changes: 26 additions & 26 deletions src/referee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use crate::channel_handler::types::{
};
use crate::common::constants::CREATE_COIN;
use crate::common::standard_coin::{
calculate_hash_of_quoted_mod_hash, curry_and_treehash, standard_solution_partial,
ChiaIdentity,
calculate_hash_of_quoted_mod_hash, curry_and_treehash, standard_solution_partial, ChiaIdentity,
};
use crate::common::types::{
chia_dialect, u64_from_atom, usize_from_atom, Aggsig, AllocEncoder, Amount,
Expand Down Expand Up @@ -1535,7 +1534,10 @@ impl RefereeMaker {
debug!("getting validation program");
debug!("my turn {}", self.is_my_turn());
debug!("state {:?}", self.state);
debug!("last stored {:?}", self.old_states[self.old_states.len()-1]);
debug!(
"last stored {:?}",
self.old_states[self.old_states.len() - 1]
);
let (_state, validation_program) = self.get_validation_program_for_their_move()?;
debug!("validation_program {validation_program:?}");
let validation_program_mod_hash = validation_program.hash();
Expand All @@ -1558,7 +1560,9 @@ impl RefereeMaker {
cldb.arg("-x");
cldb.arg(validation_program.to_program().to_hex());
cldb.arg(validator_full_args.to_hex());
cldb_out.write_all(&cldb.output().unwrap().stdout).into_gen()?;
cldb_out
.write_all(&cldb.output().unwrap().stdout)
.into_gen()?;
debug!("cldb {}", decode_string(&cldb_out));

// Error means validation should not work.
Expand Down Expand Up @@ -1649,7 +1653,8 @@ impl RefereeMaker {
if let Some(coin_string) = coin {
let slash_no_evidence = allocator.encode_atom(&[]).into_gen()?;
debug!("calling slash");
if self.check_their_turn_for_slash(allocator, slash_no_evidence, coin_string)?
if self
.check_their_turn_for_slash(allocator, slash_no_evidence, coin_string)?
.is_some()
{
// Slash isn't allowed in off chain, we'll go on chain via error.
Expand Down Expand Up @@ -1775,8 +1780,8 @@ impl RefereeMaker {
(self.fixed.amount.clone(), ()),
),
)]
.to_clvm(allocator)
.into_gen()
.to_clvm(allocator)
.into_gen()
}

fn make_slash_spend(
Expand All @@ -1793,7 +1798,7 @@ impl RefereeMaker {
slash_conditions,
&self.fixed.my_identity.synthetic_public_key,
&self.fixed.agg_sig_me_additional_data,
false
false,
)
}

Expand Down Expand Up @@ -1868,24 +1873,21 @@ impl RefereeMaker {
} else {
false
};
let created_coin =
if let Some((ph, amt)) = conditions
let created_coin = if let Some((ph, amt)) = conditions
.iter()
.filter_map(|cond| {
if let CoinCondition::CreateCoin(ph, amt) = cond {
Some((ph, amt))
} else {
None
}
}).next() {
CoinString::from_parts(
&coin_string.to_coin_id(),
&ph,
&amt
)
} else {
return Err(Error::StrErr("no coin created".to_string()));
};
})
.next()
{
CoinString::from_parts(&coin_string.to_coin_id(), &ph, &amt)
} else {
return Err(Error::StrErr("no coin created".to_string()));
};

debug!("rems in spend {conditions:?}");

Expand All @@ -1894,11 +1896,9 @@ impl RefereeMaker {
debug!("repeat: current state {:?}", self.state);

if self.is_my_turn() {
if let Some(_result) = self.check_their_turn_for_slash(
allocator,
nil,
&created_coin,
)? {
if let Some(_result) =
self.check_their_turn_for_slash(allocator, nil, &created_coin)?
{
// A repeat means that we tried a move but went on chain.
// if the move is slashable, then we should do that here.
todo!();
Expand Down Expand Up @@ -1989,8 +1989,8 @@ impl RefereeMaker {
debug!("THEIR TURN MOVE OFF CHAIN SUCCEEDED {new_puzzle_hash:?}");

let check_and_report_slash = |allocator: &mut AllocEncoder,
readable_move: NodePtr,
_mover_share: Amount| {
readable_move: NodePtr,
_mover_share: Amount| {
let nil = allocator.encode_atom(&[]).into_gen()?;
debug!("check their turn for slash");
if let Some(result) = self.check_their_turn_for_slash(allocator, nil, &created_coin)? {
Expand Down
5 changes: 4 additions & 1 deletion src/tests/peer/potato_handler_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,10 @@ fn run_calpoker_container_with_action_list_with_success_predicate(
cradles[1].opening_coin(allocator, &mut rng, parent_coin_1)?;

let global_move = |moves: &VecDeque<&GameAction>| {
matches!(moves.front(), Some(GameAction::Shutdown(_, _)) | Some(GameAction::WaitBlocks(_, _)))
matches!(
moves.front(),
Some(GameAction::Shutdown(_, _)) | Some(GameAction::WaitBlocks(_, _))
)
};

while !matches!(ending, Some(0)) {
Expand Down
6 changes: 1 addition & 5 deletions src/tests/simenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,11 +775,7 @@ fn test_referee_can_move_on_chain() {
// Make our move on chain.
let move_transaction = reftest
.my_referee
.get_transaction_for_move(
&mut allocator,
&referee_coins[0],
true,
)
.get_transaction_for_move(&mut allocator, &referee_coins[0], true)
.expect("should work");

debug!("move_transaction {move_transaction:?}");
Expand Down

0 comments on commit 362421a

Please sign in to comment.