From 4a571d510dd79cf20b388de46880c9b08c83ce73 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Sun, 3 Oct 2021 11:27:00 +0330 Subject: [PATCH] Close #85, Implement ChainHandler.fetchChainInfo() --- .../nilin/opex/bcgateway/core/spi/ChainLoader.kt | 3 +-- .../port/bcgateway/postgres/impl/ChainHandler.kt | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainLoader.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainLoader.kt index 6834b58fa..41a13a183 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainLoader.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainLoader.kt @@ -1,8 +1,7 @@ package co.nilin.opex.bcgateway.core.spi import co.nilin.opex.bcgateway.core.model.Chain -import co.nilin.opex.bcgateway.core.model.CurrencyInfo interface ChainLoader { suspend fun fetchChainInfo(chain: String): Chain -} \ No newline at end of file +} diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ChainHandler.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ChainHandler.kt index 52a88cd16..c0a3c3d67 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ChainHandler.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ChainHandler.kt @@ -1,13 +1,22 @@ package co.nilin.opex.port.bcgateway.postgres.impl +import co.nilin.opex.bcgateway.core.model.AddressType import co.nilin.opex.bcgateway.core.model.Chain +import co.nilin.opex.bcgateway.core.model.Endpoint import co.nilin.opex.bcgateway.core.spi.ChainLoader import co.nilin.opex.port.bcgateway.postgres.dao.ChainRepository +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.reactive.awaitSingle import org.springframework.stereotype.Component @Component -class ChainHandler(val chainRepository: ChainRepository): ChainLoader { +class ChainHandler(val chainRepository: ChainRepository) : ChainLoader { override suspend fun fetchChainInfo(chain: String): Chain { - TODO("Not implemented!") + val chainDao = chainRepository.findByName(chain).awaitSingle() + val addressTypes = chainRepository.findAddressTypesByName(chain) + .map { AddressType(it.id!!, it.type, it.addressRegex, it.memoRegex) }.toList() + val endpoints = chainRepository.findEndpointsByName(chain).map { Endpoint(it.url) }.toList() + return Chain(chainDao.name, addressTypes, endpoints) } -} \ No newline at end of file +}