@@ -100,9 +100,9 @@ export function makeIBCProtocolHandler(
100
100
{ timerService } ,
101
101
) {
102
102
/**
103
- * @type {Store<string, Promise<Connection>> }
103
+ * @type {Store<string, [ConnectionHandler, Promise<Connection>] > }
104
104
*/
105
- const channelKeyToConnP = makeStore ( 'CHANNEL:PORT' ) ;
105
+ const channelKeyToHandler = makeStore ( 'CHANNEL:PORT' ) ;
106
106
107
107
/**
108
108
* @typedef {Object } Counterparty
@@ -122,7 +122,7 @@ export function makeIBCProtocolHandler(
122
122
/**
123
123
* @type {Store<string, ConnectingInfo> }
124
124
*/
125
- const channelKeyToConnectingInfo = makeStore ( 'CHANNEL:PORT' ) ;
125
+ const channelKeyToInfo = makeStore ( 'CHANNEL:PORT' ) ;
126
126
127
127
/**
128
128
* @type {Set<string> }
@@ -409,7 +409,7 @@ export function makeIBCProtocolHandler(
409
409
version,
410
410
} ;
411
411
const channelKey = `${ channelID } :${ portID } ` ;
412
- channelKeyToConnectingInfo . init ( channelKey , obj ) ;
412
+ channelKeyToInfo . init ( channelKey , obj ) ;
413
413
414
414
if ( ! FIXME_ALLOW_NAIVE_RELAYS || ! chandler ) {
415
415
// Just wait until the connection handler resolves.
@@ -547,10 +547,10 @@ paths:
547
547
) ;
548
548
if ( ! waiter ) {
549
549
await E ( protocolImpl ) . isListening ( [ `/ibc-port/${ portID } ` ] ) ;
550
- channelKeyToConnectingInfo . init ( channelKey , obj ) ;
550
+ channelKeyToInfo . init ( channelKey , obj ) ;
551
551
} else {
552
552
// We have more specific information.
553
- channelKeyToConnectingInfo . set ( channelKey , obj ) ;
553
+ channelKeyToInfo . set ( channelKey , obj ) ;
554
554
}
555
555
break ;
556
556
}
@@ -569,8 +569,8 @@ paths:
569
569
connectionHops : hops ,
570
570
counterparty : { port_id : rPortID , channel_id : rChannelID } ,
571
571
counterpartyVersion : storedVersion ,
572
- } = channelKeyToConnectingInfo . get ( channelKey ) ;
573
- channelKeyToConnectingInfo . delete ( channelKey ) ;
572
+ } = channelKeyToInfo . get ( channelKey ) ;
573
+ channelKeyToInfo . delete ( channelKey ) ;
574
574
575
575
const rVersion = updatedVersion || storedVersion ;
576
576
const localAddr = `/ibc-port/${ portID } /${ order . toLowerCase ( ) } /${ version } ` ;
@@ -610,7 +610,7 @@ paths:
610
610
}
611
611
612
612
// Check for a listener for this subprotocol.
613
- const listenSearch = getPrefixes ( localAddr , '/' ) ;
613
+ const listenSearch = getPrefixes ( localAddr ) ;
614
614
const rchandler = makeIBCConnectionHandler (
615
615
channelID ,
616
616
portID ,
@@ -620,17 +620,17 @@ paths:
620
620
) ;
621
621
622
622
// Actually connect.
623
- const connP =
624
- /** @type {Promise<Connection> } */
625
- ( E ( protocolImpl ) . inbound (
626
- listenSearch ,
627
- localAddr ,
628
- remoteAddr ,
629
- rchandler ,
630
- ) ) ;
623
+ // eslint-disable-next-line prettier/prettier
624
+ const connP = /** @type {Promise<Connection> } */
625
+ ( E ( protocolImpl ) . inbound ( listenSearch , localAddr , remoteAddr , rchandler ) )
626
+ . then ( conn => {
627
+ console . info ( `FIGME: got connection` , conn ) ;
628
+ return conn ;
629
+ } ) ;
631
630
632
631
/* Stash it for later use. */
633
- channelKeyToConnP . init ( channelKey , connP ) ;
632
+ console . info ( `FIGME: Stashing ${ channelKey } ` , rchandler ) ;
633
+ channelKeyToHandler . init ( channelKey , [ rchandler , connP ] ) ;
634
634
break ;
635
635
}
636
636
@@ -643,11 +643,11 @@ paths:
643
643
} = packet ;
644
644
const channelKey = `${ channelID } :${ portID } ` ;
645
645
646
- const connP = channelKeyToConnP . get ( channelKey ) ;
646
+ const [ chandler , connP ] = channelKeyToHandler . get ( channelKey ) ;
647
647
const data = base64ToBytes ( data64 ) ;
648
648
649
- E ( connP )
650
- . send ( data )
649
+ connP
650
+ . then ( conn => E ( chandler ) . onReceive ( conn , data , chandler ) )
651
651
. then ( ack => {
652
652
const ack64 = dataToBase64 ( /** @type {Bytes } */ ( ack ) ) ;
653
653
return callIBCDevice ( 'packetExecuted' , { packet, ack : ack64 } ) ;
@@ -688,10 +688,10 @@ paths:
688
688
case 'channelCloseConfirm' : {
689
689
const { portID, channelID } = obj ;
690
690
const channelKey = `${ channelID } :${ portID } ` ;
691
- if ( channelKeyToConnP . has ( channelKey ) ) {
692
- const connP = channelKeyToConnP . get ( channelKey ) ;
693
- channelKeyToConnP . delete ( channelKey ) ;
694
- E ( connP ) . close ( ) ;
691
+ if ( channelKeyToHandler . has ( channelKey ) ) {
692
+ const [ chandler , connP ] = channelKeyToHandler . get ( channelKey ) ;
693
+ channelKeyToHandler . delete ( channelKey ) ;
694
+ connP . then ( conn => E ( chandler ) . onClose ( conn , undefined , chandler ) ) ;
695
695
}
696
696
break ;
697
697
}
0 commit comments