@@ -383,6 +383,7 @@ enum GameAction {
383
383
/// the message through to the channel handler.
384
384
#[ allow( dead_code) ]
385
385
pub struct PotatoHandler {
386
+ initiator : bool ,
386
387
have_potato : PotatoState ,
387
388
388
389
handshake_state : HandshakeState ,
@@ -456,6 +457,7 @@ impl PotatoHandler {
456
457
reward_puzzle_hash : PuzzleHash ,
457
458
) -> PotatoHandler {
458
459
PotatoHandler {
460
+ initiator : have_potato,
459
461
have_potato : if have_potato {
460
462
PotatoState :: Present
461
463
} else {
@@ -488,6 +490,10 @@ impl PotatoHandler {
488
490
}
489
491
}
490
492
493
+ pub fn is_initiator ( & self ) -> bool {
494
+ self . initiator
495
+ }
496
+
491
497
pub fn channel_handler ( & self ) -> Result < & ChannelHandler , Error > {
492
498
if let Some ( ch) = & self . channel_handler {
493
499
Ok ( ch)
@@ -608,11 +614,13 @@ impl PotatoHandler {
608
614
}
609
615
self . update_channel_coin_after_receive ( penv, & spend_info) ?;
610
616
}
611
- PeerMessage :: Accept ( game_id, _amount , sigs) => {
617
+ PeerMessage :: Accept ( game_id, amount , sigs) => {
612
618
let spend_info = {
613
- let ( env, _) = penv. env ( ) ;
614
- ch. received_potato_accept ( env, & sigs, & game_id) ?
615
- } ;
619
+ let ( env, system_interface) = penv. env ( ) ;
620
+ let result = ch. received_potato_accept ( env, & sigs, & game_id) ?;
621
+ system_interface. game_finished ( & game_id, amount) ?;
622
+ Ok ( result)
623
+ } ?;
616
624
self . update_channel_coin_after_receive ( penv, & spend_info) ?;
617
625
}
618
626
_ => {
@@ -667,6 +675,7 @@ impl PotatoHandler {
667
675
{
668
676
// Haven't got the channel coin yet.
669
677
if self . waiting_to_start {
678
+ debug ! ( "waiting to start" ) ;
670
679
return Ok ( ( ) ) ;
671
680
}
672
681
@@ -767,9 +776,10 @@ impl PotatoHandler {
767
776
let ( _, system_interface) = penv. env ( ) ;
768
777
system_interface. send_message ( & PeerMessage :: Accept (
769
778
game_id. clone ( ) ,
770
- amount,
779
+ amount. clone ( ) ,
771
780
sigs,
772
781
) ) ?;
782
+ system_interface. game_finished ( & game_id, amount) ?;
773
783
self . have_potato = PotatoState :: Absent ;
774
784
775
785
Ok ( true )
@@ -1203,6 +1213,8 @@ impl PotatoHandler {
1203
1213
match msg_envelope {
1204
1214
PeerMessage :: HandshakeF { bundle } => {
1205
1215
self . channel_finished_transaction = Some ( bundle. clone ( ) ) ;
1216
+ let ( _, system_interface) = penv. env ( ) ;
1217
+ system_interface. received_channel_offer ( & bundle) ?;
1206
1218
}
1207
1219
PeerMessage :: RequestPotato ( _) => {
1208
1220
assert ! ( matches!( self . have_potato, PotatoState :: Present ) ) ;
0 commit comments