Skip to content

Commit

Permalink
fmt + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Nov 8, 2024
1 parent 36fe1f1 commit 42b305c
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 189 deletions.
34 changes: 21 additions & 13 deletions src/channel_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use crate::channel_handler::types::{
CachedPotatoRegenerateLastHop, ChannelCoin, ChannelCoinInfo, ChannelCoinSpendInfo,
ChannelCoinSpentResult, ChannelHandlerEnv, ChannelHandlerInitiationData,
ChannelHandlerInitiationResult, ChannelHandlerPrivateKeys, ChannelHandlerUnrollSpendInfo,
CoinDataForReward, CoinSpentAccept, CoinSpentDisposition, CoinSpentMoveUp, CoinSpentResult, DispositionResult,
GameStartInfo, HandshakeResult, LiveGame, MoveResult, OnChainGameCoin, PotatoAcceptCachedData,
PotatoMoveCachedData, PotatoSignatures, ReadableMove, UnrollCoin, UnrollCoinConditionInputs, UnrollTarget
CoinDataForReward, CoinSpentAccept, CoinSpentDisposition, CoinSpentMoveUp, CoinSpentResult,
DispositionResult, GameStartInfo, HandshakeResult, LiveGame, MoveResult, OnChainGameCoin,
PotatoAcceptCachedData, PotatoMoveCachedData, PotatoSignatures, ReadableMove, UnrollCoin,
UnrollCoinConditionInputs, UnrollTarget,
};
use crate::common::constants::CREATE_COIN;
use crate::common::standard_coin::{
Expand All @@ -29,8 +30,8 @@ use crate::common::standard_coin::{
};
use crate::common::types::{
usize_from_atom, Aggsig, Amount, BrokenOutCoinSpendInfo, CoinCondition, CoinID, CoinSpend,
CoinString, Error, GameID, Hash, IntoErr, Node, PrivateKey, Program, PublicKey, Puzzle, PuzzleHash,
Sha256tree, Spend, SpendRewardResult, ToQuotedProgram,
CoinString, Error, GameID, Hash, IntoErr, Node, PrivateKey, Program, PublicKey, Puzzle,
PuzzleHash, Sha256tree, Spend, SpendRewardResult, ToQuotedProgram,
};
use crate::referee::RefereeMaker;

Expand Down Expand Up @@ -138,10 +139,9 @@ impl ChannelHandler {
&self,
env: &mut ChannelHandlerEnv<R>,
) -> Result<NodePtr, Error> {
self.unroll.coin.make_curried_unroll_puzzle(
env,
&self.get_aggregate_unroll_public_key()
)
self.unroll
.coin
.make_curried_unroll_puzzle(env, &self.get_aggregate_unroll_public_key())
}

fn unroll_coin_condition_inputs(
Expand Down Expand Up @@ -1037,7 +1037,10 @@ impl ChannelHandler {
.make_unroll_puzzle_solution(env, &self.get_aggregate_unroll_public_key())?;
let solution_program = Program::from_nodeptr(env.allocator, unroll_puzzle_solution)?;

debug!("get_unroll_coin_transaction {:?}", solution_program.to_hex());
debug!(
"get_unroll_coin_transaction {:?}",
solution_program.to_hex()
);
Ok(ChannelCoinSpentResult {
transaction: Spend {
puzzle: Puzzle::from_nodeptr(env.allocator, curried_unroll_puzzle)?,
Expand Down Expand Up @@ -1291,7 +1294,7 @@ impl ChannelHandler {
let unroll_coin = CoinString::from_parts(
&parent_coin.to_coin_id(),
&unroll_puzzle_hash,
&(self.my_out_of_game_balance.clone() + self.their_out_of_game_balance.clone())
&(self.my_out_of_game_balance.clone() + self.their_out_of_game_balance.clone()),
);

let disposition =
Expand All @@ -1310,11 +1313,16 @@ impl ChannelHandler {
pub fn set_state_for_coins<R: Rng>(
&mut self,
env: &mut ChannelHandlerEnv<R>,
coins: &[OnChainGameCoin]
coins: &[OnChainGameCoin],
) -> Result<(), Error> {
let mut res = Vec::new();
for game_coin in coins.iter() {
if let Some(live_game) = self.live_games.iter_mut().filter(|f| game_coin.game_id_up == f.game_id).next() {
if let Some(live_game) = self
.live_games
.iter_mut()
.filter(|f| game_coin.game_id_up == f.game_id)
.next()
{
res.append(&mut live_game.set_state_for_coin(env.allocator, game_coin)?);
} else {
// XXX Used to exist, needs ressurection from the cache to potentially replay
Expand Down
15 changes: 7 additions & 8 deletions src/channel_handler/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ impl LiveGame {
pub fn set_state_for_coin(
&mut self,
allocator: &mut AllocEncoder,
coin: &OnChainGameCoin
coin: &OnChainGameCoin,
) -> Result<Vec<LiveGameReplay>, Error> {
let want_ph =
if let Some((_, ph, _)) = coin.coin_string_up.as_ref().and_then(|cs| cs.to_parts()) {
Expand All @@ -962,19 +962,18 @@ impl LiveGame {
todo!();
};

let referee_puzzle_hash = self.referee_maker.curried_referee_puzzle_hash_for_validator(
allocator,
true,
)?;
let referee_puzzle_hash = self
.referee_maker
.curried_referee_puzzle_hash_for_validator(allocator, true)?;

if referee_puzzle_hash == want_ph {
return Ok(vec![]);
}

while self.referee_maker.rewind()? {
let new_puzzle_hash = self.referee_maker.curried_referee_puzzle_hash_for_validator(
allocator, true
)?;
let new_puzzle_hash = self
.referee_maker
.curried_referee_puzzle_hash_for_validator(allocator, true)?;

if new_puzzle_hash == want_ph {
todo!();
Expand Down
49 changes: 22 additions & 27 deletions src/peer_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use log::debug;
use rand::Rng;

use crate::channel_handler::runner::channel_handler_env;
use crate::channel_handler::types::{ChannelHandlerEnv, ChannelHandlerPrivateKeys, OnChainGameCoin, ReadableMove};
use crate::channel_handler::types::{
ChannelHandlerEnv, ChannelHandlerPrivateKeys, OnChainGameCoin, ReadableMove,
};
use crate::common::constants::CREATE_COIN;
use crate::common::standard_coin::{
sign_agg_sig_me, solution_for_conditions, standard_solution_partial, ChiaIdentity,
Expand Down Expand Up @@ -272,10 +274,7 @@ impl PacketSender for SynchronousGameCradleState {

impl WalletSpendInterface for SynchronousGameCradleState {
/// Enqueue an outbound transaction.
fn spend_transaction_and_add_fee(
&mut self,
bundle: &SpendBundle,
) -> Result<(), Error> {
fn spend_transaction_and_add_fee(&mut self, bundle: &SpendBundle) -> Result<(), Error> {
self.outbound_transactions.push_back(bundle.clone());
Ok(())
}
Expand Down Expand Up @@ -488,14 +487,15 @@ impl SynchronousGameCradle {

let ch = self.peer.channel_handler()?;
let channel_coin = ch.state_channel_coin();
let channel_coin_amt = if let Some((ch_parent, ph, amt)) = channel_coin.coin_string().to_parts() {
// We can be sure we've got the right puzzle hash separately.
assert_eq!(ph, channel_puzzle_hash);
assert_eq!(ch_parent, parent.to_coin_id());
amt
} else {
return Err(Error::StrErr("no channel coin".to_string()));
};
let channel_coin_amt =
if let Some((ch_parent, ph, amt)) = channel_coin.coin_string().to_parts() {
// We can be sure we've got the right puzzle hash separately.
assert_eq!(ph, channel_puzzle_hash);
assert_eq!(ch_parent, parent.to_coin_id());
amt
} else {
return Err(Error::StrErr("no channel coin".to_string()));
};

let conditions_clvm = [(
CREATE_COIN,
Expand Down Expand Up @@ -596,15 +596,14 @@ impl SynchronousGameCradle {
#[cfg(test)]
pub fn replace_last_message<F>(&mut self, f: F) -> Result<(), Error>
where
F: FnOnce(&PeerMessage) -> Result<PeerMessage, Error>
F: FnOnce(&PeerMessage) -> Result<PeerMessage, Error>,
{
// Grab and decode the message.
let msg =
if let Some(msg) = self.state.outbound_messages.pop_back() {
msg
} else {
todo!();
};
let msg = if let Some(msg) = self.state.outbound_messages.pop_back() {
msg
} else {
todo!();
};

let doc = bson::Document::from_reader(&mut msg.as_slice()).into_gen()?;
let msg_envelope: PeerMessage = bson::from_bson(bson::Bson::Document(doc)).into_gen()?;
Expand Down Expand Up @@ -752,7 +751,7 @@ impl GameCradle for SynchronousGameCradle {

swap(
&mut result.coin_solution_requests,
&mut self.state.coin_solution_requests
&mut self.state.coin_solution_requests,
);
self.state.coin_solution_requests.clear();

Expand Down Expand Up @@ -799,7 +798,6 @@ impl GameCradle for SynchronousGameCradle {
return Ok(result);
}
}

}

if let Some(ph) = self.state.channel_puzzle_hash.clone() {
Expand Down Expand Up @@ -842,10 +840,7 @@ impl GameCradle for SynchronousGameCradle {
env: &mut env,
system_interface: &mut self.state,
};
self.peer.coin_puzzle_and_solution(
&mut penv,
coin_id,
puzzle_and_solution,
)
self.peer
.coin_puzzle_and_solution(&mut penv, coin_id, puzzle_and_solution)
}
}
Loading

0 comments on commit 42b305c

Please sign in to comment.