Skip to content

Commit 973e1f9

Browse files
committed
Some clippy traffic, update the debug game a bit
1 parent 6951054 commit 973e1f9

File tree

6 files changed

+87
-100
lines changed

6 files changed

+87
-100
lines changed

resources/debug_game_handler.clsp

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
)
4242
)
4343

44-
(defun one-or-zero (X) (i X X 0x00))
45-
4644
(defun do_my_turn (MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO readable_new_move amount state entropy)
4745
(assign
4846

@@ -51,7 +49,7 @@
5149
new_validation_program_hash (shatree state "this is not right") ;; XXX just anything
5250

5351
(list
54-
(concat (one-or-zero set_cheated) set_share)
52+
(logior (logand 1 set_cheated) (ash set_share 1))
5553
validation_program
5654
new_validation_program_hash
5755
(c set_share set_cheated)
@@ -65,7 +63,7 @@
6563

6664
(defun do_their_turn (MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO amount last_state new_move new_validation_info_hash new_max_move_size new_mover_share)
6765
(assign
68-
set_cheated (+ (substr new_move 0 1))
66+
set_cheated (logand new_move 1)
6967

7068
(if set_cheated
7169
(c 2 SLASH_INFO)

src/channel_handler/game_handler.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn run_code(
141141
allocator: &mut AllocEncoder,
142142
code: NodePtr,
143143
env: NodePtr,
144-
debug: bool,
144+
_debug: bool,
145145
) -> Result<NodePtr, Error> {
146146
run_program(allocator.allocator(), &chia_dialect(), code, env, 0)
147147
.into_gen()
@@ -269,7 +269,7 @@ impl GameHandler {
269269

270270
Ok(MyTurnResult {
271271
waiting_driver: GameHandler::their_driver_from_nodeptr(pl[6]),
272-
move_data: move_data,
272+
move_data,
273273
validation_program: pl[1],
274274
validation_program_hash,
275275
state: pl[3],
@@ -378,8 +378,8 @@ impl MessageHandler {
378378
}
379379
pub fn run(
380380
&self,
381-
allocator: &mut AllocEncoder,
382-
inputs: &MessageInputs,
381+
_allocator: &mut AllocEncoder,
382+
_inputs: &MessageInputs,
383383
) -> Result<ReadableUX, Error> {
384384
todo!();
385385
}

src/channel_handler/handler.rs

+45-54
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl ChannelHandler {
515515
self.create_conditions_and_signature_of_channel_coin(env, state_number_for_spend)?;
516516

517517
let new_game_coins_on_chain: Vec<(PuzzleHash, Amount)> = self
518-
.get_new_game_coins_on_chain(env, None, None, None)
518+
.get_new_game_coins_on_chain(env, None, &[], None)
519519
.iter()
520520
.filter_map(|ngc| ngc.coin_string_up.as_ref().and_then(|c| c.to_parts()))
521521
.map(|(_, puzzle_hash, amount)| (puzzle_hash, amount))
@@ -1141,48 +1141,46 @@ impl ChannelHandler {
11411141
},
11421142
false,
11431143
))
1144-
} else {
1145-
if state_number == self.unroll_state_number {
1146-
// Timeout
1147-
let (curried_unroll_puzzle, unroll_puzzle_solution) = self
1148-
.make_unroll_puzzle_solution(
1149-
env,
1150-
self.default_conditions_for_unroll_coin_spend.to_nodeptr(),
1151-
)?;
1152-
1153-
Ok((
1154-
TransactionBundle {
1155-
puzzle: Puzzle::from_nodeptr(curried_unroll_puzzle),
1156-
solution: unroll_puzzle_solution,
1157-
signature: Aggsig::default(),
1158-
},
1159-
true,
1160-
))
1161-
} else if state_number == self.current_state_number {
1162-
// Different timeout, construct the conditions based on the current
1163-
// state. (different because we're not using the conditions we
1164-
// have cached).
1165-
let (conditions, _) = self.create_conditions_and_signature_of_channel_coin(
1144+
} else if state_number == self.unroll_state_number {
1145+
// Timeout
1146+
let (curried_unroll_puzzle, unroll_puzzle_solution) = self
1147+
.make_unroll_puzzle_solution(
11661148
env,
1167-
self.current_state_number,
1149+
self.default_conditions_for_unroll_coin_spend.to_nodeptr(),
11681150
)?;
1169-
let (curried_unroll_puzzle, unroll_puzzle_solution) =
1170-
self.make_unroll_puzzle_solution(env, conditions)?;
1171-
1172-
Ok((
1173-
TransactionBundle {
1174-
puzzle: Puzzle::from_nodeptr(curried_unroll_puzzle),
1175-
solution: unroll_puzzle_solution,
1176-
signature: Aggsig::default(),
1177-
},
1178-
true,
1179-
))
1180-
} else {
1181-
return Err(Error::StrErr(format!(
1182-
"Unhandled relationship between state numbers {state_number} {}",
1183-
self.unroll_state_number
1184-
)));
1185-
}
1151+
1152+
Ok((
1153+
TransactionBundle {
1154+
puzzle: Puzzle::from_nodeptr(curried_unroll_puzzle),
1155+
solution: unroll_puzzle_solution,
1156+
signature: Aggsig::default(),
1157+
},
1158+
true,
1159+
))
1160+
} else if state_number == self.current_state_number {
1161+
// Different timeout, construct the conditions based on the current
1162+
// state. (different because we're not using the conditions we
1163+
// have cached).
1164+
let (conditions, _) = self.create_conditions_and_signature_of_channel_coin(
1165+
env,
1166+
self.current_state_number,
1167+
)?;
1168+
let (curried_unroll_puzzle, unroll_puzzle_solution) =
1169+
self.make_unroll_puzzle_solution(env, conditions)?;
1170+
1171+
Ok((
1172+
TransactionBundle {
1173+
puzzle: Puzzle::from_nodeptr(curried_unroll_puzzle),
1174+
solution: unroll_puzzle_solution,
1175+
signature: Aggsig::default(),
1176+
},
1177+
true,
1178+
))
1179+
} else {
1180+
Err(Error::StrErr(format!(
1181+
"Unhandled relationship between state numbers {state_number} {}",
1182+
self.unroll_state_number
1183+
)))
11861184
}
11871185
}
11881186

@@ -1221,7 +1219,7 @@ impl ChannelHandler {
12211219
Some(CachedPotatoRegenerateLastHop::PotatoCreatedGame(
12221220
ids,
12231221
our_contrib,
1224-
their_contrib,
1222+
_their_contrib,
12251223
)) => {
12261224
// Add amount contributed to vanilla balance
12271225
// Skip game when generating result.
@@ -1307,9 +1305,9 @@ impl ChannelHandler {
13071305

13081306
pub fn get_new_game_coins_on_chain<R: Rng>(
13091307
&self,
1310-
env: &mut ChannelHandlerEnv<R>,
1308+
_env: &mut ChannelHandlerEnv<R>,
13111309
unroll_coin: Option<&CoinID>,
1312-
skip_game: Option<&GameID>,
1310+
skip_game: &[GameID],
13131311
skip_coin_id: Option<&GameID>,
13141312
) -> Vec<OnChainGameCoin> {
13151313
// It's ok to not have a proper coin id here when we only want
@@ -1318,7 +1316,7 @@ impl ChannelHandler {
13181316

13191317
self.live_games
13201318
.iter()
1321-
.filter(|game| skip_game != Some(&game.game_id))
1319+
.filter(|game| !skip_game.contains(&game.game_id))
13221320
.map(|game| {
13231321
let coin = if skip_coin_id == Some(&game.game_id) {
13241322
None
@@ -1385,22 +1383,15 @@ impl ChannelHandler {
13851383
return Err(Error::StrErr("Unconvertible state number".to_string()));
13861384
};
13871385

1388-
let our_parity = self.unroll_state_number & 1;
1389-
let their_parity = state_number & 1;
1390-
1391-
let mut skip_game = None;
1392-
let mut skip_coin_id = None;
1393-
let mut contributed_adjustment = Amount::default();
1394-
13951386
let disposition =
13961387
self.get_cached_disposition_for_spent_result(env, unroll_coin, state_number)?;
13971388

13981389
// return list of triples of game_id, coin_id, referee maker pulling from a list of pairs of (id, ref maker)
13991390
let new_game_coins_on_chain = self.get_new_game_coins_on_chain(
14001391
env,
14011392
Some(&unroll_coin.to_coin_id()),
1402-
skip_game.as_ref(),
1403-
skip_coin_id.as_ref(),
1393+
&disposition.as_ref().map(|d| d.skip_game.clone()).unwrap_or_default(),
1394+
disposition.as_ref().and_then(|d| d.skip_coin_id.as_ref()),
14041395
);
14051396

14061397
// coin with = parent is the unroll coin id and whose puzzle hash is ref and amount is my vanilla amount.

src/channel_handler/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl ReadableMove {
7777
impl ToClvm<NodePtr> for ReadableMove {
7878
fn to_clvm(
7979
&self,
80-
encoder: &mut impl ClvmEncoder<Node = NodePtr>,
80+
_encoder: &mut impl ClvmEncoder<Node = NodePtr>,
8181
) -> Result<NodePtr, ToClvmError> {
8282
Ok(self.0)
8383
}

src/common/types.rs

+32-34
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ pub struct RefereeID(usize);
466466
/// Error type
467467
#[derive(Debug)]
468468
pub enum Error {
469-
ClvmError(EvalErr),
470-
IoError(io::Error),
469+
ClvmErr(EvalErr),
470+
IoErr(io::Error),
471471
BasicError,
472472
SyntaxErr(SyntaxErr),
473473
EncodeErr(ToClvmError),
@@ -635,7 +635,7 @@ pub trait ErrToError {
635635

636636
impl ErrToError for EvalErr {
637637
fn into_gen(self) -> Error {
638-
Error::ClvmError(self)
638+
Error::ClvmErr(self)
639639
}
640640
}
641641

@@ -654,7 +654,7 @@ impl ErrToError for SyntaxErr {
654654

655655
impl ErrToError for io::Error {
656656
fn into_gen(self) -> Error {
657-
Error::IoError(self)
657+
Error::IoErr(self)
658658
}
659659
}
660660

@@ -711,37 +711,35 @@ fn parse_condition(allocator: &mut AllocEncoder, condition: NodePtr) -> Option<C
711711
}
712712
PublicKey::from_bytes(fixed)
713713
};
714-
if exploded.len() > 2 {
715-
if matches!(
716-
(
717-
allocator.allocator().sexp(exploded[0]),
718-
allocator.allocator().sexp(exploded[1]),
719-
allocator.allocator().sexp(exploded[2])
720-
),
721-
(SExp::Atom, SExp::Atom, SExp::Atom)
722-
) {
723-
let atoms: Vec<Vec<u8>> = exploded
724-
.iter()
725-
.take(3)
726-
.map(|a| allocator.allocator().atom(*a).to_vec())
727-
.collect();
728-
if *atoms[0] == AGG_SIG_UNSAFE_ATOM {
729-
if let Ok(pk) = public_key_from_bytes(&atoms[1]) {
730-
return Some(CoinCondition::AggSigUnsafe(pk, atoms[2].to_vec()));
731-
}
732-
} else if *atoms[0] == AGG_SIG_ME_ATOM {
733-
if let Ok(pk) = public_key_from_bytes(&atoms[1]) {
734-
return Some(CoinCondition::AggSigMe(pk, atoms[2].to_vec()));
735-
}
736-
} else if *atoms[0] == CREATE_COIN_ATOM {
737-
return Some(CoinCondition::CreateCoin(PuzzleHash::from_hash(
738-
Hash::from_slice(&atoms[1]),
739-
)));
740-
} else if *atoms[0] == REM_ATOM {
741-
return Some(CoinCondition::Rem(
742-
atoms.iter().map(|a| a.to_vec()).collect(),
743-
));
714+
if exploded.len() > 2 && matches!(
715+
(
716+
allocator.allocator().sexp(exploded[0]),
717+
allocator.allocator().sexp(exploded[1]),
718+
allocator.allocator().sexp(exploded[2])
719+
),
720+
(SExp::Atom, SExp::Atom, SExp::Atom)
721+
) {
722+
let atoms: Vec<Vec<u8>> = exploded
723+
.iter()
724+
.take(3)
725+
.map(|a| allocator.allocator().atom(*a).to_vec())
726+
.collect();
727+
if *atoms[0] == AGG_SIG_UNSAFE_ATOM {
728+
if let Ok(pk) = public_key_from_bytes(&atoms[1]) {
729+
return Some(CoinCondition::AggSigUnsafe(pk, atoms[2].to_vec()));
730+
}
731+
} else if *atoms[0] == AGG_SIG_ME_ATOM {
732+
if let Ok(pk) = public_key_from_bytes(&atoms[1]) {
733+
return Some(CoinCondition::AggSigMe(pk, atoms[2].to_vec()));
744734
}
735+
} else if *atoms[0] == CREATE_COIN_ATOM {
736+
return Some(CoinCondition::CreateCoin(PuzzleHash::from_hash(
737+
Hash::from_slice(&atoms[1]),
738+
)));
739+
} else if *atoms[0] == REM_ATOM {
740+
return Some(CoinCondition::Rem(
741+
atoms.iter().map(|a| a.to_vec()).collect(),
742+
));
745743
}
746744
}
747745

src/referee/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl RefereeMaker {
196196
my_private_key: my_private_key.clone(),
197197
timeout: game_start_info.timeout.clone(),
198198
amount: game_start_info.amount.clone(),
199-
nonce: nonce,
199+
nonce,
200200

201201
states: [state.clone(), state],
202202
is_my_turn: game_start_info.game_handler.is_my_turn(),
@@ -484,7 +484,7 @@ impl RefereeMaker {
484484

485485
(|current_state: &RefereeMakerGameState| {
486486
match &current_state.game_handler {
487-
GameHandler::MyTurnHandler(h) => {
487+
GameHandler::MyTurnHandler(_h) => {
488488
// It is my turn
489489
if current_state.mover_share != Amount::default() {
490490
// And we have a mover share.
@@ -493,7 +493,7 @@ impl RefereeMaker {
493493

494494
(true, Amount::default())
495495
}
496-
GameHandler::TheirTurnHandler(h) => {
496+
GameHandler::TheirTurnHandler(_h) => {
497497
// Their turn
498498
if current_state.mover_share != amount {
499499
// There is some left over.

0 commit comments

Comments
 (0)