@@ -649,46 +649,46 @@ impl RefereeMaker {
649
649
agg_sig_me_additional_data : & Hash ,
650
650
) -> Result < ( TransactionBundle , CoinString ) , Error > {
651
651
let puzzle_reveal = {
652
- let previous_args = {
653
- let previous_state = self . previous_state ( ) ;
654
- let puzzle_hash = curry_referee_puzzle_hash (
655
- allocator ,
656
- & self . referee_coin_puzzle_hash ,
657
- & RefereePuzzleArgs {
658
- // XXX check polarity
659
- mover_puzzle_hash : self . my_identity . puzzle_hash . clone ( ) ,
660
- waiter_puzzle_hash : self . their_referee_puzzle_hash . clone ( ) ,
661
- timeout : self . timeout . clone ( ) ,
662
- amount : self . amount . clone ( ) ,
663
- referee_coin_puzzle_hash : self . referee_coin_puzzle_hash . clone ( ) ,
664
- game_move : previous_state . game_move . clone ( ) ,
665
- nonce : self . nonce ,
666
- previous_validation_info_hash : previous_state
667
- . previous_validation_program_hash
668
- . clone ( ) ,
669
- } ,
670
- ) ? ;
671
- let inner_conditions =
672
- // XXX puzzle_reveal
673
- ( CREATE_COIN , ( puzzle_hash. clone ( ) , ( self . amount . clone ( ) , ( ) ) ) ) . to_clvm ( allocator) . into_gen ( ) ?;
674
- let ( solution, sig) =
675
- standard_solution ( allocator, & self . my_identity . private_key , inner_conditions) ?;
676
- let args_list: Vec < Node > = [
677
- previous_state. game_move . move_made . to_clvm ( allocator) . into_gen ( ) ?,
678
- previous_state
679
- . game_move . validation_info_hash
680
- . to_clvm ( allocator)
681
- . into_gen ( ) ?,
682
- previous_state. game_move . mover_share . to_clvm ( allocator) . into_gen ( ) ?,
683
- previous_state. game_move . max_move_size . to_clvm ( allocator) . into_gen ( ) ?,
684
- puzzle_hash. to_clvm ( allocator) . into_gen ( ) ?,
685
- solution,
686
- ]
652
+ let previous_state = self . previous_state ( ) ;
653
+ let puzzle_hash = curry_referee_puzzle_hash (
654
+ allocator ,
655
+ & self . referee_coin_puzzle_hash ,
656
+ & RefereePuzzleArgs {
657
+ // XXX check polarity
658
+ mover_puzzle_hash : self . my_identity . puzzle_hash . clone ( ) ,
659
+ waiter_puzzle_hash : self . their_referee_puzzle_hash . clone ( ) ,
660
+ timeout : self . timeout . clone ( ) ,
661
+ amount : self . amount . clone ( ) ,
662
+ referee_coin_puzzle_hash : self . referee_coin_puzzle_hash . clone ( ) ,
663
+ game_move : previous_state . game_move . clone ( ) ,
664
+ nonce : self . nonce ,
665
+ previous_validation_info_hash : previous_state
666
+ . previous_validation_program_hash
667
+ . clone ( ) ,
668
+ } ,
669
+ ) ? ;
670
+
671
+ let inner_conditions =
672
+ // XXX puzzle_reveal
673
+ ( CREATE_COIN , ( puzzle_hash. clone ( ) , ( self . amount . clone ( ) , ( ) ) ) ) . to_clvm ( allocator) . into_gen ( ) ?;
674
+ let ( solution, sig) =
675
+ standard_solution ( allocator, & self . my_identity . private_key , inner_conditions) ?;
676
+ let args_list: Vec < Node > = [
677
+ previous_state. game_move . move_made . to_clvm ( allocator) . into_gen ( ) ?,
678
+ previous_state
679
+ . game_move . validation_info_hash
680
+ . to_clvm ( allocator)
681
+ . into_gen ( ) ?,
682
+ previous_state. game_move . mover_share . to_clvm ( allocator) . into_gen ( ) ?,
683
+ previous_state. game_move . max_move_size . to_clvm ( allocator) . into_gen ( ) ?,
684
+ puzzle_hash. to_clvm ( allocator) . into_gen ( ) ?,
685
+ solution,
686
+ ]
687
687
. into_iter ( )
688
688
. map ( |n| Node ( n) )
689
689
. collect ( ) ;
690
- args_list . to_clvm ( allocator ) . into_gen ( ) ?
691
- } ;
690
+
691
+ let previous_args = args_list . to_clvm ( allocator ) . into_gen ( ) ? ;
692
692
693
693
if let Some ( ( bundle, cs_out) ) = self . get_transaction (
694
694
allocator,
@@ -850,6 +850,7 @@ impl RefereeMaker {
850
850
)
851
851
} ;
852
852
853
+ // Retrieve evidence from their turn handler.
853
854
let result = handler. call_their_turn_driver (
854
855
allocator,
855
856
& TheirTurnInputs {
@@ -868,6 +869,30 @@ impl RefereeMaker {
868
869
869
870
match result {
870
871
TheirTurnResult :: MakeMove ( handler, readable_move, message) => {
872
+ // Mover puzzle turns the given solution into coin conditions
873
+ // that pay the game's amount to us. It checks whether the
874
+ // originally curried mover puzzle hash is the sha256tree of the
875
+ // mover puzzle.
876
+ //
877
+ // This referee expects the mover puzzle to be a standard-like
878
+ // puzzle or at least take standard coin arguments including the
879
+ // list of conditions it produces itself.
880
+ //
881
+ // In case this succeeds, we'll direct the result to our mover
882
+ // puzzle, which sets our identity for the game and is a value-
883
+ // holding coin spendable by us.
884
+
885
+ // let validator_move_args = ValidatorMoveArgs {
886
+ // game_move: details.clone(),
887
+ // mover_puzzle: self.identity.puzzle.clone(),
888
+ // solution:
889
+ // };
890
+
891
+ // let validator_result = self.run_validator_for_their_move(
892
+ // allocator,
893
+ // validator_move_args
894
+ // );
895
+
871
896
// XXX check for slashing.
872
897
self . update_for_their_turn_move (
873
898
allocator,
@@ -907,12 +932,31 @@ impl RefereeMaker {
907
932
}
908
933
}
909
934
910
- fn target_puzzle_hash_for_slash (
935
+ // It me.
936
+ fn target_puzzle_hash_for_slash ( & self ) -> PuzzleHash {
937
+ self . my_identity . puzzle_hash . clone ( )
938
+ }
939
+
940
+ fn slashing_coin_solution (
911
941
& self ,
912
942
allocator : & mut AllocEncoder ,
913
- ) -> Result < PuzzleHash , Error > {
914
- let target_inner_puzzle = puzzle_for_pk ( allocator, & self . my_identity . public_key ) ?;
915
- puzzle_hash_for_pk ( allocator, & self . my_identity . public_key )
943
+ state : NodePtr ,
944
+ validation_program : Puzzle ,
945
+ slash_solution : NodePtr ,
946
+ coin_solution_after_slash : NodePtr
947
+ ) -> Result < NodePtr , Error > {
948
+ (
949
+ Node ( state. clone ( ) ) ,
950
+ (
951
+ validation_program. clone ( ) ,
952
+ (
953
+ self . target_puzzle_hash_for_slash ( ) ,
954
+ ( Node ( slash_solution) , ( Node ( coin_solution_after_slash) , ( ) ) ) ,
955
+ ) ,
956
+ ) ,
957
+ )
958
+ . to_clvm ( allocator)
959
+ . into_gen ( )
916
960
}
917
961
918
962
fn make_slash_for_their_turn (
@@ -938,23 +982,19 @@ impl RefereeMaker {
938
982
current_state. validation_program . clone ( ) ,
939
983
)
940
984
} ;
985
+
941
986
let reward_amount = self . amount . clone ( ) - current_mover_share;
942
987
if reward_amount == Amount :: default ( ) {
943
988
return Ok ( TheirTurnCoinSpentResult :: Slash ( SlashOutcome :: NoReward ) ) ;
944
989
}
945
990
946
- let slashing_coin_solution = (
947
- Node ( state. clone ( ) ) ,
948
- (
949
- Node ( validation_program. clone ( ) ) ,
950
- (
951
- self . target_puzzle_hash_for_slash ( allocator) ?,
952
- ( Node ( slash_solution) , ( Node ( solution) , ( ) ) ) ,
953
- ) ,
954
- ) ,
955
- )
956
- . to_clvm ( allocator)
957
- . into_gen ( ) ?;
991
+ let slashing_coin_solution = self . slashing_coin_solution (
992
+ allocator,
993
+ state,
994
+ Puzzle :: from_nodeptr ( validation_program) ,
995
+ slash_solution,
996
+ solution
997
+ ) ?;
958
998
959
999
let coin_string_of_output_coin =
960
1000
CoinString :: from_parts ( & coin_string. to_coin_id ( ) , & new_puzzle_hash, & reward_amount) ;
@@ -1069,7 +1109,7 @@ impl RefereeMaker {
1069
1109
let slash_conditions = (
1070
1110
CREATE_COIN ,
1071
1111
(
1072
- self . target_puzzle_hash_for_slash ( allocator ) ? ,
1112
+ self . target_puzzle_hash_for_slash ( ) ,
1073
1113
( self . amount . clone ( ) , ( ) ) ,
1074
1114
) ,
1075
1115
)
0 commit comments