From d844bcb60fc37ab231fb77e1eec7a5482c53423d Mon Sep 17 00:00:00 2001 From: Ebrahim Hosseiny Fadaee Date: Mon, 20 Sep 2021 19:19:57 +0430 Subject: [PATCH 1/3] Close #64, Implement reserved addresses (#71) --- .../co/nilin/opex/bcgateway/core/model/Address.kt | 10 ++++++++-- .../postgres/dao/ReservedAddressRepository.kt | 12 +++++++++++- .../postgres/impl/ReservedAddressHandlerImpl.kt | 13 +++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Address.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Address.kt index ff7a125fe..4efb82bb0 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Address.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Address.kt @@ -2,7 +2,13 @@ package co.nilin.opex.bcgateway.core.model data class AddressType(val id: Long, val type: String, val addressRegex: String, val memoRegex: String) data class ReservedAddress(val address: String, val memo: String?, val type: AddressType) -data class AssignedAddress(val uuid: String, val address: String, val memo: String?, val type: AddressType, val chains: MutableList ){ +data class AssignedAddress( + val uuid: String, + val address: String, + val memo: String?, + val type: AddressType, + val chains: MutableList +) { override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -24,4 +30,4 @@ data class AssignedAddress(val uuid: String, val address: String, val memo: Stri result = 31 * result + type.hashCode() return result } -} \ 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/dao/ReservedAddressRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ReservedAddressRepository.kt index a48a80366..738a701fe 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ReservedAddressRepository.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ReservedAddressRepository.kt @@ -1,8 +1,18 @@ package co.nilin.opex.port.bcgateway.postgres.dao import co.nilin.opex.port.bcgateway.postgres.model.ReservedAddressModel +import org.springframework.data.r2dbc.repository.Modifying +import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.stereotype.Repository +import reactor.core.publisher.Mono @Repository -interface ReservedAddressRepository : ReactiveCrudRepository \ No newline at end of file +interface ReservedAddressRepository : ReactiveCrudRepository { + @Query("select * from reserved_addresses where address_type = :addressType order by id DESC") + fun peekFirstAdded(addressType: Long): Mono + + @Modifying + @Query("delete from reserved_addresses where address = :address and (memo is null or memo = :memo)") + fun remove(address: String, memo: String?): Mono +} diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ReservedAddressHandlerImpl.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ReservedAddressHandlerImpl.kt index ed2e0e547..bb7d0f54a 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ReservedAddressHandlerImpl.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ReservedAddressHandlerImpl.kt @@ -3,15 +3,20 @@ package co.nilin.opex.port.bcgateway.postgres.impl import co.nilin.opex.bcgateway.core.model.AddressType import co.nilin.opex.bcgateway.core.model.ReservedAddress import co.nilin.opex.bcgateway.core.spi.ReservedAddressHandler +import co.nilin.opex.port.bcgateway.postgres.dao.ReservedAddressRepository +import kotlinx.coroutines.reactive.awaitFirst +import kotlinx.coroutines.reactive.awaitFirstOrNull import org.springframework.stereotype.Component @Component -class ReservedAddressHandlerImpl: ReservedAddressHandler { +class ReservedAddressHandlerImpl(private val reservedAddressRepository: ReservedAddressRepository) : + ReservedAddressHandler { override suspend fun peekReservedAddress(addressType: AddressType): ReservedAddress? { - TODO("Not yet implemented") + return reservedAddressRepository.peekFirstAdded(addressType.id) + .map { ReservedAddress(it.address, it.memo, addressType) }.awaitFirstOrNull() } override suspend fun remove(reservedAddress: ReservedAddress) { - TODO("Not yet implemented") + reservedAddressRepository.remove(reservedAddress.address, reservedAddress.memo).awaitFirst() } -} \ No newline at end of file +} From 5a5924b3fbb0643aa04830b2024a0a2028c7997a Mon Sep 17 00:00:00 2001 From: Ebrahim Hosseiny Fadaee Date: Mon, 20 Sep 2021 19:22:46 +0430 Subject: [PATCH 2/3] Close #26, Add chain endpoint proxy (#72) * Add ChainEndpointProxyFinderImpl * Add chain proxy module --- .../core/spi/ChainEndpointProxyFinder.kt | 4 +- .../bc-chain-proxy/.gitignore | 36 ++++++++ .../bc-gateway-ports/bc-chain-proxy/pom.xml | 90 +++++++++++++++++++ .../impl/ChainEndpointProxyImpl.kt | 12 +++ .../bc-persister-postgres/pom.xml | 8 +- .../bcgateway/postgres/dao/ChainRepository.kt | 5 +- .../impl/ChainEndpointProxyFinderImpl.kt | 18 ++++ BlockchainGateway/pom.xml | 1 + 8 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 BlockchainGateway/bc-gateway-ports/bc-chain-proxy/.gitignore create mode 100644 BlockchainGateway/bc-gateway-ports/bc-chain-proxy/pom.xml create mode 100644 BlockchainGateway/bc-gateway-ports/bc-chain-proxy/src/main/kotlin/co.nilin.opex.port.bcgateway.chainproxy/impl/ChainEndpointProxyImpl.kt create mode 100644 BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ChainEndpointProxyFinderImpl.kt diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainEndpointProxyFinder.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainEndpointProxyFinder.kt index 7db1ba870..f4762765a 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainEndpointProxyFinder.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainEndpointProxyFinder.kt @@ -1,5 +1,5 @@ package co.nilin.opex.bcgateway.core.spi interface ChainEndpointProxyFinder { - suspend fun findChainEndpointProxy(chainName: String):ChainEndpointProxy -} \ No newline at end of file + suspend fun findChainEndpointProxy(chainName: String): ChainEndpointProxy +} diff --git a/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/.gitignore b/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/.gitignore new file mode 100644 index 000000000..f4e066ca5 --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/.gitignore @@ -0,0 +1,36 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ +!/.mvn/ + +.DS_Store diff --git a/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/pom.xml b/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/pom.xml new file mode 100644 index 000000000..ca4affcdc --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/pom.xml @@ -0,0 +1,90 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.4.4 + + + 4.0.0 + + co.nilin.opex.external + bc-chain-proxy + 1.0-SNAPSHOT + + + 1.8 + 1.4.31 + ${version} + + + + + org.springframework.boot + spring-boot-starter + + + + io.projectreactor.kotlin + reactor-kotlin-extensions + + + org.jetbrains.kotlin + kotlin-reflect + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + + + co.nilin.opex.external + bc-gateway-core + ${bc-gateway.version} + + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + -Xjsr305=strict + + + spring + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + diff --git a/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/src/main/kotlin/co.nilin.opex.port.bcgateway.chainproxy/impl/ChainEndpointProxyImpl.kt b/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/src/main/kotlin/co.nilin.opex.port.bcgateway.chainproxy/impl/ChainEndpointProxyImpl.kt new file mode 100644 index 000000000..bf9e4e217 --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-chain-proxy/src/main/kotlin/co.nilin.opex.port.bcgateway.chainproxy/impl/ChainEndpointProxyImpl.kt @@ -0,0 +1,12 @@ +package co.nilin.opex.port.bcgateway.chainproxy.impl + +import co.nilin.opex.bcgateway.core.model.ChainSyncRecord +import co.nilin.opex.bcgateway.core.model.Endpoint +import co.nilin.opex.bcgateway.core.spi.ChainEndpointProxy +import org.springframework.stereotype.Component + +class ChainEndpointProxyImpl(private val endpoints: List) : ChainEndpointProxy { + override suspend fun syncTransfers(filter: ChainEndpointProxy.DepositFilter): ChainSyncRecord { + TODO("Not yet implemented") + } +} diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/pom.xml b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/pom.xml index 321effaa2..f289f6e96 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/pom.xml +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/pom.xml @@ -67,7 +67,13 @@ reactor-test test - + + co.nilin.opex.external + bc-chain-proxy + 1.0-SNAPSHOT + compile + + ${project.basedir}/src/main/kotlin diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainRepository.kt index 9395b112a..299ca7127 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainRepository.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainRepository.kt @@ -7,10 +7,11 @@ import kotlinx.coroutines.flow.Flow import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.stereotype.Repository +import reactor.core.publisher.Mono @Repository interface ChainRepository : ReactiveCrudRepository { - fun findByName(name: String): Flow + fun findByName(name: String): Mono @Query( """ @@ -25,4 +26,4 @@ interface ChainRepository : ReactiveCrudRepository { @Query("select * from chain_endpoints where chain_name = :name") fun findEndpointsByName(name: String): Flow -} \ 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/ChainEndpointProxyFinderImpl.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ChainEndpointProxyFinderImpl.kt new file mode 100644 index 000000000..b0873c9f9 --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ChainEndpointProxyFinderImpl.kt @@ -0,0 +1,18 @@ +package co.nilin.opex.port.bcgateway.postgres.impl + +import co.nilin.opex.bcgateway.core.model.Endpoint +import co.nilin.opex.bcgateway.core.spi.ChainEndpointProxy +import co.nilin.opex.bcgateway.core.spi.ChainEndpointProxyFinder +import co.nilin.opex.port.bcgateway.chainproxy.impl.ChainEndpointProxyImpl +import co.nilin.opex.port.bcgateway.postgres.dao.ChainRepository +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.toList +import org.springframework.stereotype.Component + +@Component +class ChainEndpointProxyFinderImpl(private val chainRepository: ChainRepository) : ChainEndpointProxyFinder { + override suspend fun findChainEndpointProxy(chainName: String): ChainEndpointProxy { + val endpoints = chainRepository.findEndpointsByName(chainName).map { Endpoint(it.url) }.toList() + return ChainEndpointProxyImpl(endpoints) + } +} diff --git a/BlockchainGateway/pom.xml b/BlockchainGateway/pom.xml index d2090befe..7c8b77ddf 100644 --- a/BlockchainGateway/pom.xml +++ b/BlockchainGateway/pom.xml @@ -13,5 +13,6 @@ bc-gateway-core bc-gateway-app bc-gateway-ports/bc-persister-postgres + bc-gateway-ports/bc-chain-proxy From 9b8605f9ef80c5a68a04a954b5aabb49558b8910 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Tue, 21 Sep 2021 11:54:27 +0430 Subject: [PATCH 3/3] Fix #75, bc-gateway port conflict --- Deployment/docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Deployment/docker-compose.yml b/Deployment/docker-compose.yml index e10c538b7..13ed5fb6a 100644 --- a/Deployment/docker-compose.yml +++ b/Deployment/docker-compose.yml @@ -328,7 +328,7 @@ services: dockerfile: Dockerfile ports: - 127.0.0.1:8095:8095 - - 127.0.0.1:1051:1044 + - 127.0.0.1:1052:1044 environment: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - SPRING_PROFILES_ACTIVE=docker @@ -349,4 +349,4 @@ services: condition: on-failure networks: opex: - driver: bridge \ No newline at end of file + driver: bridge