@@ -48,7 +48,7 @@ class Swaps extends EventEmitter {
4848 constructor ( private logger : Logger ,
4949 private models : Models ,
5050 private pool : Pool ,
51- private swapClients : { [ currency : string ] : BaseClient | undefined } ,
51+ private swapClients : Map < string , BaseClient > ,
5252 ) {
5353 super ( ) ;
5454 this . repository = new SwapRepository ( this . models ) ;
@@ -116,8 +116,8 @@ class Swaps extends EventEmitter {
116116 */
117117 public isPairSupported = ( pairId : string ) : boolean => {
118118 const currencies = pairId . split ( '/' ) ;
119- const baseCurrencyClient = this . swapClients [ currencies [ 0 ] ] ;
120- const quoteCurrencyClient = this . swapClients [ currencies [ 1 ] ] ;
119+ const baseCurrencyClient = this . swapClients . get ( currencies [ 0 ] ) ;
120+ const quoteCurrencyClient = this . swapClients . get ( currencies [ 1 ] ) ;
121121 return baseCurrencyClient !== undefined && baseCurrencyClient . isConnected ( ) &&
122122 quoteCurrencyClient !== undefined && quoteCurrencyClient . isConnected ( ) ;
123123 }
@@ -140,13 +140,20 @@ class Swaps extends EventEmitter {
140140 * @returns undefined if the setup is verified, otherwise an error message
141141 */
142142 private checkPeerIdentifiers = ( deal : SwapDeal , peer : Peer ) => {
143- // TODO: this verification should happen before we accept orders from the peer and should check Raiden as well
144- if ( ! peer . getIdentifier ( SwapClient . Lnd , deal . takerCurrency ) ) {
145- return 'peer did not provide an LND PubKey for ' + deal . takerCurrency ;
143+ // TODO: this verification should happen before we accept orders from the peer
144+ const takerSwapClient = this . swapClients . get ( deal . takerCurrency ) ;
145+ if ( ! takerSwapClient ) {
146+ return `unable to get swap client for ${ deal . takerCurrency } ` ;
146147 }
147-
148- if ( ! peer . getIdentifier ( SwapClient . Lnd , deal . makerCurrency ) ) {
149- return 'peer did not provide an LND PubKey for ' + deal . makerCurrency ;
148+ if ( ! peer . getIdentifier ( takerSwapClient . type , deal . takerCurrency ) ) {
149+ return `peer did not provide an identifier for ${ deal . takerCurrency } ` ;
150+ }
151+ const makerSwapClient = this . swapClients . get ( deal . makerCurrency ) ;
152+ if ( ! makerSwapClient ) {
153+ return `unable to get swap client for ${ deal . makerCurrency } ` ;
154+ }
155+ if ( ! peer . getIdentifier ( makerSwapClient . type , deal . makerCurrency ) ) {
156+ return `peer did not provide an identifier for ${ deal . makerCurrency } ` ;
150157 }
151158 return ;
152159 }
@@ -197,7 +204,7 @@ class Swaps extends EventEmitter {
197204 const { makerCurrency } = Swaps . deriveCurrencies ( maker . pairId , maker . isBuy ) ;
198205 const { makerAmount } = Swaps . calculateSwapAmounts ( taker . quantity , maker . price , maker . isBuy , maker . pairId ) ;
199206
200- const swapClient = this . swapClients [ makerCurrency ] ;
207+ const swapClient = this . swapClients . get ( makerCurrency ) ;
201208 if ( ! swapClient ) throw new Error ( 'swap client not found' ) ;
202209
203210 const peer = this . pool . getPeer ( maker . peerPubKey ) ;
@@ -263,10 +270,10 @@ class Swaps extends EventEmitter {
263270
264271 const quantity = Math . min ( maker . quantity , taker . quantity ) ;
265272 const { makerAmount, takerAmount } = Swaps . calculateSwapAmounts ( quantity , maker . price , maker . isBuy , maker . pairId ) ;
266- const clientType = this . swapClients [ makerCurrency ] ! . type ;
273+ const clientType = this . swapClients . get ( makerCurrency ) ! . type ;
267274 const destination = peer . getIdentifier ( clientType , makerCurrency ) ! ;
268275
269- const takerCltvDelta = this . swapClients [ takerCurrency ] ! . cltvDelta ;
276+ const takerCltvDelta = this . swapClients . get ( takerCurrency ) ! . cltvDelta ;
270277
271278 const preimage = await randomBytes ( 32 ) ;
272279
@@ -337,7 +344,7 @@ class Swaps extends EventEmitter {
337344 const { makerAmount, takerAmount } = Swaps . calculateSwapAmounts ( quantity , price , isBuy , requestBody . pairId ) ;
338345 const { makerCurrency, takerCurrency } = Swaps . deriveCurrencies ( requestBody . pairId , isBuy ) ;
339346
340- const swapClient = this . swapClients [ takerCurrency ] ;
347+ const swapClient = this . swapClients . get ( takerCurrency ) ;
341348 if ( ! swapClient ) {
342349 await this . sendErrorToPeer ( peer , rHash , SwapFailureReason . SwapClientNotSetup , 'Unsupported taker currency' , requestPacket . header . id ) ;
343350 return false ;
@@ -414,8 +421,8 @@ class Swaps extends EventEmitter {
414421
415422 const routeCltvDelta = deal . makerToTakerRoutes [ 0 ] . getTotalTimeLock ( ) - height ;
416423
417- const makerClientCltvDelta = this . swapClients [ makerCurrency ] ! . cltvDelta ;
418- const takerClientCltvDelta = this . swapClients [ takerCurrency ] ! . cltvDelta ;
424+ const makerClientCltvDelta = this . swapClients . get ( makerCurrency ) ! . cltvDelta ;
425+ const takerClientCltvDelta = this . swapClients . get ( takerCurrency ) ! . cltvDelta ;
419426
420427 // cltvDelta can't be zero for swap clients (checked in constructor)
421428 const cltvDeltaFactor = makerClientCltvDelta / takerClientCltvDelta ;
@@ -426,7 +433,7 @@ class Swaps extends EventEmitter {
426433 }
427434
428435 const responseBody : packets . SwapAcceptedPacketBody = {
429- makerCltvDelta : deal . makerCltvDelta || 0 ,
436+ makerCltvDelta : deal . makerCltvDelta || 1 ,
430437 rHash : requestBody . rHash ,
431438 quantity : requestBody . proposedQuantity ,
432439 } ;
@@ -480,7 +487,7 @@ class Swaps extends EventEmitter {
480487 }
481488 }
482489
483- const swapClient = this . swapClients [ deal . makerCurrency ] ;
490+ const swapClient = this . swapClients . get ( deal . makerCurrency ) ;
484491 if ( ! swapClient ) {
485492 // We checked that we had a swap client for both currencies involved when the swap was initiated. Still...
486493 return ;
@@ -576,7 +583,7 @@ class Swaps extends EventEmitter {
576583 // As the maker, I need to forward the payment to the other chain
577584 this . logger . debug ( 'Executing maker code' ) ;
578585
579- const swapClient = this . swapClients [ deal . takerCurrency ] ! ;
586+ const swapClient = this . swapClients . get ( deal . takerCurrency ) ! ;
580587
581588 try {
582589 this . setDealPhase ( deal , SwapPhase . SendingAmount ) ;
0 commit comments