@@ -182,25 +182,22 @@ fn curry_referee_puzzle_hash(
182
182
/// Mover puzzle is a wallet puzzle for an ordinary value coin and the solution
183
183
/// is next to it.
184
184
///
185
- pub struct ValidatorMoveArgs < ' a > {
186
- pub new_move : & ' a [ u8 ] ,
187
- pub new_validation_info_hash : Hash ,
188
- pub new_mover_share : Amount ,
189
- pub new_max_move_size : usize ,
185
+ pub struct ValidatorMoveArgs {
186
+ pub game_move : GameMoveDetails ,
190
187
pub mover_puzzle : Program ,
191
188
pub solution : NodePtr
192
189
}
193
190
194
- impl < ' a > ValidatorMoveArgs < ' a > {
191
+ impl ValidatorMoveArgs {
195
192
pub fn to_nodeptr (
196
193
& self ,
197
194
allocator : & mut AllocEncoder
198
195
) -> Result < NodePtr , Error > {
199
196
let args: & [ NodePtr ] = & [
200
- allocator. encode_atom ( self . new_move ) . into_gen ( ) ?,
201
- self . new_validation_info_hash . to_clvm ( allocator) . into_gen ( ) ?,
202
- self . new_mover_share . to_clvm ( allocator) . into_gen ( ) ?,
203
- self . new_max_move_size . to_clvm ( allocator) . into_gen ( ) ?,
197
+ allocator. encode_atom ( & self . game_move . move_made ) . into_gen ( ) ?,
198
+ self . game_move . validation_info_hash . to_clvm ( allocator) . into_gen ( ) ?,
199
+ self . game_move . mover_share . to_clvm ( allocator) . into_gen ( ) ?,
200
+ self . game_move . max_move_size . to_clvm ( allocator) . into_gen ( ) ?,
204
201
self . mover_puzzle . to_clvm ( allocator) . into_gen ( ) ?,
205
202
self . solution
206
203
] ;
@@ -216,10 +213,12 @@ struct RefereeMakerGameState {
216
213
pub state : NodePtr ,
217
214
pub validation_program : NodePtr ,
218
215
pub game_handler : GameHandler ,
219
- pub previous_state : NodePtr ,
216
+
220
217
// Details of the move that triggered this state change
221
218
pub game_move : GameMoveDetails ,
222
219
220
+ pub previous_state : NodePtr ,
221
+
223
222
// Ensure we copy this when we update RefereeMaker::current_state
224
223
pub previous_validation_program_hash : Hash ,
225
224
}
@@ -479,19 +478,15 @@ impl RefereeMaker {
479
478
// Agg sig me on the solution of the referee_coin_puzzle.
480
479
// When it invokes the validation program, it passes through args as the full
481
480
// argument set.
482
- pub fn curry_referee_puzzle (
481
+ fn curry_referee_puzzle (
483
482
& self ,
484
483
allocator : & mut AllocEncoder ,
485
- coin_string : & CoinString ,
486
484
curried_args : & RefereePuzzleArgs ,
487
485
// args from referee.clsp
488
486
args : Option < NodePtr > ,
489
- agg_sig_additional_data : & Hash ,
490
- ) -> Result < TransactionBundle , Error > {
491
- let public_key = private_to_public_key ( & self . my_identity . private_key ) ;
492
- let my_referee_puzzle = puzzle_for_pk ( allocator, & public_key) ?;
493
- let puzzle = CurriedProgram {
494
- program : my_referee_puzzle. clone ( ) ,
487
+ ) -> Result < Puzzle , Error > {
488
+ Ok ( Puzzle :: from_nodeptr ( CurriedProgram {
489
+ program : self . my_identity . puzzle . clone ( ) ,
495
490
args : clvm_curried_args ! (
496
491
curried_args. mover_puzzle_hash. clone( ) ,
497
492
curried_args. waiter_puzzle_hash. clone( ) ,
@@ -507,22 +502,45 @@ impl RefereeMaker {
507
502
) ,
508
503
}
509
504
. to_clvm ( allocator)
510
- . into_gen ( ) ?;
511
- let solution = args. unwrap_or_else ( || allocator. allocator ( ) . null ( ) ) ;
512
- let solution_hash = Node ( solution) . sha256tree ( allocator) ;
513
-
514
- let signature = sign_agg_sig_me (
515
- & self . my_identity . private_key ,
516
- & solution_hash. bytes ( ) ,
517
- & coin_string. to_coin_id ( ) ,
518
- agg_sig_additional_data,
519
- ) ;
505
+ . into_gen ( ) ?) )
506
+ }
520
507
521
- Ok ( TransactionBundle {
522
- puzzle : Puzzle :: from_nodeptr ( puzzle) ,
523
- solution,
524
- signature,
525
- } )
508
+ pub fn curried_referee_puzzle_for_validator (
509
+ & self ,
510
+ allocator : & mut AllocEncoder ,
511
+ args : Option < NodePtr > ,
512
+ ) -> Result < Puzzle , Error > {
513
+ let current_state = self . current_state ( ) ;
514
+ let my_turn =
515
+ matches ! ( current_state. game_handler, GameHandler :: MyTurnHandler ( _) ) ;
516
+ let mover_puzzle_hash = if my_turn {
517
+ self . my_identity . puzzle_hash . clone ( )
518
+ } else {
519
+ self . their_referee_puzzle_hash . clone ( )
520
+ } ;
521
+ let waiter_puzzle_hash = if my_turn {
522
+ self . their_referee_puzzle_hash . clone ( )
523
+ } else {
524
+ self . my_identity . puzzle_hash . clone ( )
525
+ } ;
526
+
527
+ self . curry_referee_puzzle (
528
+ allocator,
529
+ & RefereePuzzleArgs {
530
+ mover_puzzle_hash,
531
+ waiter_puzzle_hash,
532
+ timeout : self . timeout . clone ( ) ,
533
+ amount : self . amount . clone ( ) ,
534
+ referee_coin_puzzle_hash : self . referee_coin_puzzle_hash . clone ( ) ,
535
+ nonce : self . nonce ,
536
+
537
+ game_move : current_state. game_move . clone ( ) ,
538
+ previous_validation_info_hash : current_state
539
+ . previous_validation_program_hash
540
+ . clone ( ) ,
541
+ } ,
542
+ args,
543
+ )
526
544
}
527
545
528
546
// Ensure this returns
@@ -571,37 +589,26 @@ impl RefereeMaker {
571
589
// XXX do this differently based on args.is_none()
572
590
// because that is a move transaction with no reward.
573
591
let transaction_bundle = {
574
- let current_state = self . current_state ( ) ;
575
- let mover_puzzle_hash = if my_turn {
576
- self . my_identity . puzzle_hash . clone ( )
577
- } else {
578
- self . their_referee_puzzle_hash . clone ( )
579
- } ;
580
- let waiter_puzzle_hash = if my_turn {
581
- self . their_referee_puzzle_hash . clone ( )
582
- } else {
583
- self . my_identity . puzzle_hash . clone ( )
584
- } ;
585
-
586
- self . curry_referee_puzzle (
592
+ let puzzle = self . curried_referee_puzzle_for_validator (
587
593
allocator,
588
- coin_string,
589
- & RefereePuzzleArgs {
590
- mover_puzzle_hash,
591
- waiter_puzzle_hash,
592
- timeout : self . timeout . clone ( ) ,
593
- amount : self . amount . clone ( ) ,
594
- referee_coin_puzzle_hash : self . referee_coin_puzzle_hash . clone ( ) ,
595
- nonce : self . nonce ,
594
+ args
595
+ ) ?;
596
596
597
- game_move : current_state. game_move . clone ( ) ,
598
- previous_validation_info_hash : current_state
599
- . previous_validation_program_hash
600
- . clone ( ) ,
601
- } ,
602
- args,
597
+ let solution = args. unwrap_or_else ( || allocator. allocator ( ) . null ( ) ) ;
598
+ let solution_hash = Node ( solution) . sha256tree ( allocator) ;
599
+
600
+ let signature = sign_agg_sig_me (
601
+ & self . my_identity . private_key ,
602
+ & solution_hash. bytes ( ) ,
603
+ & coin_string. to_coin_id ( ) ,
603
604
agg_sig_me_additional_data,
604
- ) ?
605
+ ) ;
606
+
607
+ TransactionBundle {
608
+ puzzle,
609
+ solution,
610
+ signature,
611
+ }
605
612
} ;
606
613
607
614
let output_coin_string = CoinString :: from_parts (
@@ -805,19 +812,11 @@ impl RefereeMaker {
805
812
Ok ( ( ) )
806
813
}
807
814
808
- pub fn curried_referee_coin_puzzle_hash (
809
- & mut self ,
810
- allocator : & mut AllocEncoder ,
811
- validator_move_args : & ValidatorMoveArgs ,
812
- ) -> Result < PuzzleHash , Error > {
813
- todo ! ( ) ;
814
- }
815
-
816
815
pub fn run_validator_for_their_move (
817
816
& mut self ,
818
817
allocator : & mut AllocEncoder ,
819
818
validator_move_args : & ValidatorMoveArgs
820
- ) -> Result < Option < SlashOutcome > , Error > {
819
+ ) -> Result < ( ) , Error > {
821
820
let validation_program = self . current_state ( ) . validation_program ;
822
821
let validator_move_converted = validator_move_args. to_nodeptr ( allocator) ?;
823
822
let ran_validator =
@@ -828,8 +827,7 @@ impl RefereeMaker {
828
827
validator_move_converted,
829
828
0
830
829
) . into_gen ( ) ?. 1 ;
831
- eprintln ! ( "ran_validator {}" , disassemble( allocator. allocator( ) , ran_validator, None ) ) ;
832
- todo ! ( ) ;
830
+ Ok ( ( ) )
833
831
}
834
832
835
833
pub fn their_turn_move_off_chain (
@@ -1058,10 +1056,8 @@ impl RefereeMaker {
1058
1056
} ;
1059
1057
let new_puzzle = self . curry_referee_puzzle (
1060
1058
allocator,
1061
- coin_string,
1062
1059
& ref_puzzle_args,
1063
1060
None ,
1064
- agg_sig_me_additional_data,
1065
1061
) ?;
1066
1062
let new_puzzle_hash =
1067
1063
curry_referee_puzzle_hash ( allocator, & self . referee_coin_puzzle_hash , & ref_puzzle_args) ?;
@@ -1144,7 +1140,7 @@ impl RefereeMaker {
1144
1140
self . make_slash_for_their_turn (
1145
1141
allocator,
1146
1142
coin_string,
1147
- & new_puzzle. puzzle ,
1143
+ & new_puzzle,
1148
1144
& new_puzzle_hash,
1149
1145
full_slash_solution,
1150
1146
slash_solution,
@@ -1175,7 +1171,7 @@ impl RefereeMaker {
1175
1171
TheirTurnResult :: Slash ( solution, sig) => self . make_slash_for_their_turn (
1176
1172
allocator,
1177
1173
coin_string,
1178
- & new_puzzle. puzzle ,
1174
+ & new_puzzle,
1179
1175
& new_puzzle_hash,
1180
1176
full_slash_solution,
1181
1177
solution,
0 commit comments