@@ -4,11 +4,13 @@ import co.nilin.opex.api.core.inout.AssignResponse
44import co.nilin.opex.api.core.inout.CurrencyImplementation
55import co.nilin.opex.api.core.inout.DepositDetails
66import co.nilin.opex.api.core.spi.BlockchainGatewayProxy
7+ import co.nilin.opex.api.ports.proxy.config.ProxyDispatchers
78import co.nilin.opex.api.ports.proxy.data.AssignAddressRequest
89import co.nilin.opex.api.ports.proxy.data.DepositDetailsRequest
910import co.nilin.opex.common.utils.LoggerDelegate
1011import kotlinx.coroutines.reactive.awaitFirstOrElse
1112import kotlinx.coroutines.reactor.awaitSingleOrNull
13+ import kotlinx.coroutines.withContext
1214import org.springframework.beans.factory.annotation.Value
1315import org.springframework.http.MediaType
1416import org.springframework.stereotype.Component
@@ -28,42 +30,48 @@ class BlockchainGatewayProxyImpl(private val client: WebClient) : BlockchainGate
2830
2931 override suspend fun assignAddress (uuid : String , currency : String , chain : String ): AssignResponse ? {
3032 logger.info(" calling bc-gateway assign" )
31- return client.post()
32- .uri(URI .create(" $baseUrl /v1/address/assign" ))
33- .accept(MediaType .APPLICATION_JSON )
34- .contentType(MediaType .APPLICATION_JSON )
35- .body(Mono .just(AssignAddressRequest (uuid, currency, chain)))
36- .retrieve()
37- .onStatus({ t -> t.isError }, { it.createException() })
38- .bodyToMono(AssignResponse ::class .java)
39- .awaitSingleOrNull()
33+ return withContext(ProxyDispatchers .general) {
34+ client.post()
35+ .uri(URI .create(" $baseUrl /v1/address/assign" ))
36+ .accept(MediaType .APPLICATION_JSON )
37+ .contentType(MediaType .APPLICATION_JSON )
38+ .body(Mono .just(AssignAddressRequest (uuid, currency, chain)))
39+ .retrieve()
40+ .onStatus({ t -> t.isError }, { it.createException() })
41+ .bodyToMono(AssignResponse ::class .java)
42+ .awaitSingleOrNull()
43+ }
4044 }
4145
4246 override suspend fun getDepositDetails (refs : List <String >): List <DepositDetails > {
4347 logger.info(" calling bc-gateway deposit details" )
44- return client.post()
45- .uri(URI .create(" $baseUrl /deposit/find/all" ))
46- .accept(MediaType .APPLICATION_JSON )
47- .contentType(MediaType .APPLICATION_JSON )
48- .body(Mono .just(DepositDetailsRequest (refs)))
49- .retrieve()
50- .onStatus({ t -> t.isError }, { it.createException() })
51- .bodyToFlux<DepositDetails >()
52- .collectList()
53- .awaitFirstOrElse { emptyList() }
48+ return withContext(ProxyDispatchers .general) {
49+ client.post()
50+ .uri(URI .create(" $baseUrl /deposit/find/all" ))
51+ .accept(MediaType .APPLICATION_JSON )
52+ .contentType(MediaType .APPLICATION_JSON )
53+ .body(Mono .just(DepositDetailsRequest (refs)))
54+ .retrieve()
55+ .onStatus({ t -> t.isError }, { it.createException() })
56+ .bodyToFlux<DepositDetails >()
57+ .collectList()
58+ .awaitFirstOrElse { emptyList() }
59+ }
5460 }
5561
5662 override suspend fun getCurrencyImplementations (currency : String? ): List <CurrencyImplementation > {
5763 logger.info(" calling bc-gateway chain details" )
58- return client.get()
59- .uri(" $baseUrl /currency/chains" ) {
60- it.queryParam(" currency" , currency)
61- it.build()
62- }.accept(MediaType .APPLICATION_JSON )
63- .retrieve()
64- .onStatus({ t -> t.isError }, { it.createException() })
65- .bodyToFlux<CurrencyImplementation >()
66- .collectList()
67- .awaitFirstOrElse { emptyList() }
64+ return withContext(ProxyDispatchers .general) {
65+ client.get()
66+ .uri(" $baseUrl /currency/chains" ) {
67+ it.queryParam(" currency" , currency)
68+ it.build()
69+ }.accept(MediaType .APPLICATION_JSON )
70+ .retrieve()
71+ .onStatus({ t -> t.isError }, { it.createException() })
72+ .bodyToFlux<CurrencyImplementation >()
73+ .collectList()
74+ .awaitFirstOrElse { emptyList() }
75+ }
6876 }
6977}
0 commit comments