Skip to content

Commit 5db4fdd

Browse files
Close #85, Implement ChainHandler.fetchChainInfo() (#86)
1 parent be44f2b commit 5db4fdd

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

  • BlockchainGateway
    • bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi
    • bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package co.nilin.opex.bcgateway.core.spi
22

33
import co.nilin.opex.bcgateway.core.model.Chain
4-
import co.nilin.opex.bcgateway.core.model.CurrencyInfo
54

65
interface ChainLoader {
76
suspend fun fetchChainInfo(chain: String): Chain
8-
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
package co.nilin.opex.port.bcgateway.postgres.impl
22

3+
import co.nilin.opex.bcgateway.core.model.AddressType
34
import co.nilin.opex.bcgateway.core.model.Chain
5+
import co.nilin.opex.bcgateway.core.model.Endpoint
46
import co.nilin.opex.bcgateway.core.spi.ChainLoader
57
import co.nilin.opex.port.bcgateway.postgres.dao.ChainRepository
8+
import kotlinx.coroutines.flow.map
9+
import kotlinx.coroutines.flow.toList
10+
import kotlinx.coroutines.reactive.awaitSingle
611
import org.springframework.stereotype.Component
712

813
@Component
9-
class ChainHandler(val chainRepository: ChainRepository): ChainLoader {
14+
class ChainHandler(val chainRepository: ChainRepository) : ChainLoader {
1015
override suspend fun fetchChainInfo(chain: String): Chain {
11-
TODO("Not implemented!")
16+
val chainDao = chainRepository.findByName(chain).awaitSingle()
17+
val addressTypes = chainRepository.findAddressTypesByName(chain)
18+
.map { AddressType(it.id!!, it.type, it.addressRegex, it.memoRegex) }.toList()
19+
val endpoints = chainRepository.findEndpointsByName(chain).map { Endpoint(it.url) }.toList()
20+
return Chain(chainDao.name, addressTypes, endpoints)
1221
}
13-
}
22+
}

0 commit comments

Comments
 (0)