diff --git a/BlockchainGateway/bc-gateway-app/pom.xml b/BlockchainGateway/bc-gateway-app/pom.xml index fcd1200f7..71355c3df 100644 --- a/BlockchainGateway/bc-gateway-app/pom.xml +++ b/BlockchainGateway/bc-gateway-app/pom.xml @@ -1,227 +1,232 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.4.4 - - - co.nilin.opex.external - bc-gateway-app - 1.0-SNAPSHOT - bc-gateway-app - Blockchain gateway app of Opex + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.4.4 + + + co.nilin.opex.external + bc-gateway-app + 1.0-SNAPSHOT + bc-gateway-app + Blockchain gateway app of Opex - - 1.8 - 1.4.31 - ${version} - ${version} - 2020.0.2 - + + 1.8 + 1.4.31 + ${version} + ${version} + 2020.0.2 + - - - org.springframework.boot - spring-boot-starter-webflux - - - com.fasterxml.jackson.module - jackson-module-kotlin - - - - org.jetbrains.kotlin - kotlin-stdlib - - - 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 - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - io.projectreactor - reactor-test - test - - - org.springframework.cloud - spring-cloud-starter-consul-all - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-starter-oauth2-resource-server - - - org.bouncycastle - bcprov-jdk15on - 1.60 - - - co.nilin.opex.external - bc-gateway-core - ${bc-gateway.version} - - + + + org.springframework.boot + spring-boot-starter-webflux + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + org.jetbrains.kotlin + kotlin-stdlib + + + 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 + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + io.projectreactor + reactor-test + test + + + org.springframework.cloud + spring-cloud-starter-consul-all + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + + + org.bouncycastle + bcprov-jdk15on + 1.60 + + + co.nilin.opex.external + bc-gateway-core + ${bc-gateway.version} + + + co.nilin.opex.external + bc-gateway-persister-postgres + ${bc-gateway.version} + + - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - 2.18 - - - ${skip.unit.tests} - - - **/*IntegrationTest.java - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-test-source - generate-test-sources - - add-test-source - - - - src/test/java - - - - - compile - - add-source - - - - src/main/java - - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - - -Xjsr305=strict - - - spring - - 1.8 - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - compile - compile - - compile - - - - testCompile - test-compile - - testCompile - - - - - - opex-bc-gateway - + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18 + + + ${skip.unit.tests} + + + **/*IntegrationTest.java + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-test-source + generate-test-sources + + add-test-source + + + + src/test/java + + + + + compile + + add-source + + + + src/main/java + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + + -Xjsr305=strict + + + spring + + 1.8 + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + compile + compile + + compile + + + + testCompile + test-compile + + testCompile + + + + + + opex-bc-gateway + diff --git a/BlockchainGateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/AppConfig.kt b/BlockchainGateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/AppConfig.kt index fc5c07cff..58cc98ade 100644 --- a/BlockchainGateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/AppConfig.kt +++ b/BlockchainGateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/AppConfig.kt @@ -21,9 +21,9 @@ class AppConfig { fun assignAddressService( currencyLoader: CurrencyLoader, assignedAddressHandler: AssignedAddressHandler, - cachedAddressHandler: CachedAddressHandler + reservedAddressHandler: ReservedAddressHandler ): AssignAddressService { - return AssignAddressServiceImpl(currencyLoader, assignedAddressHandler, cachedAddressHandler) + return AssignAddressServiceImpl(currencyLoader, assignedAddressHandler, reservedAddressHandler) } @Bean diff --git a/BlockchainGateway/bc-gateway-app/src/main/resources/application-docker.yml b/BlockchainGateway/bc-gateway-app/src/main/resources/application-docker.yml index 37996be60..ffbf14176 100644 --- a/BlockchainGateway/bc-gateway-app/src/main/resources/application-docker.yml +++ b/BlockchainGateway/bc-gateway-app/src/main/resources/application-docker.yml @@ -1,4 +1,4 @@ -server.port: 8091 +server.port: 8095 spring: application: name: opex-bc-gateway diff --git a/BlockchainGateway/bc-gateway-app/src/main/resources/application.yml b/BlockchainGateway/bc-gateway-app/src/main/resources/application.yml index 2c544a1f5..c21510415 100644 --- a/BlockchainGateway/bc-gateway-app/src/main/resources/application.yml +++ b/BlockchainGateway/bc-gateway-app/src/main/resources/application.yml @@ -1,4 +1,4 @@ -server.port: 8091 +server.port: 8095 spring: application: name: opex-bc-gateway diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/api/InfoService.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/api/InfoService.kt index 6286ab830..838e2a7d8 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/api/InfoService.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/api/InfoService.kt @@ -3,6 +3,6 @@ package co.nilin.opex.bcgateway.core.api import co.nilin.opex.bcgateway.core.model.CurrencyInfo interface InfoService { - suspend fun countCachedAddresses(): Long + suspend fun countReservedAddresses(): Long suspend fun getCurrencyInfo(): CurrencyInfo } \ No newline at end of file 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 14572e8e9..ff7a125fe 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 @@ -1,7 +1,7 @@ package co.nilin.opex.bcgateway.core.model data class AddressType(val id: Long, val type: String, val addressRegex: String, val memoRegex: String) -data class CachedAddress(val address: String, val memo: String?, val type: AddressType) +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 ){ override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Chain.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Chain.kt index 73875ced3..c591687f8 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Chain.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Chain.kt @@ -6,12 +6,13 @@ import java.time.LocalDateTime data class Endpoint(val url: String) data class Chain(val name: String, val addressTypes: List, val endpoints: List) data class ChainSyncSchedule(val chainName: String, val retryTime: LocalDateTime, val delay: Long) -data class ChainSyncRecord(val chainName: String - , val time: LocalDateTime - , val endpoint: Endpoint - , val latestBlock: Long? - , val success: Boolean - , val error: String? - , val records: List +data class ChainSyncRecord( + val chainName: String, + val time: LocalDateTime, + val endpoint: Endpoint, + val latestBlock: Long?, + val success: Boolean, + val error: String?, + val records: List ) diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImpl.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImpl.kt index 95dddaf43..ef4cb3a45 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImpl.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImpl.kt @@ -6,14 +6,14 @@ import co.nilin.opex.bcgateway.core.model.AssignedAddress import co.nilin.opex.bcgateway.core.model.Chain import co.nilin.opex.bcgateway.core.model.Currency import co.nilin.opex.bcgateway.core.spi.AssignedAddressHandler -import co.nilin.opex.bcgateway.core.spi.CachedAddressHandler +import co.nilin.opex.bcgateway.core.spi.ReservedAddressHandler import co.nilin.opex.bcgateway.core.spi.CurrencyLoader import java.lang.RuntimeException class AssignAddressServiceImpl( val currencyLoader: CurrencyLoader, val assignedAddressHandler: AssignedAddressHandler, - val cachedAddressHandler: CachedAddressHandler + val reservedAddressHandler: ReservedAddressHandler ) : AssignAddressService { override suspend fun assignAddress(user: String, currency: Currency): List { @@ -42,19 +42,19 @@ class AssignAddressServiceImpl( } result.add(assigned) } else { - val cachedAddress = cachedAddressHandler.peekCachedAddress(addressType) - if (cachedAddress != null) { + val reservedAddress = reservedAddressHandler.peekReservedAddress(addressType) + if (reservedAddress != null) { val newAssigned = AssignedAddress( user, - cachedAddress.address, - cachedAddress.memo, + reservedAddress.address, + reservedAddress.memo, addressType, chainAddressTypeMap.get(addressType)!! ) - cachedAddressHandler.remove(cachedAddress) + reservedAddressHandler.remove(reservedAddress) result.add(newAssigned) } else - throw RuntimeException("No cached address available for $addressType") + throw RuntimeException("No reserved address available for $addressType") } } diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/InfoServiceImpl.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/InfoServiceImpl.kt index 5f4d53f49..e600f2369 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/InfoServiceImpl.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/InfoServiceImpl.kt @@ -4,7 +4,7 @@ import co.nilin.opex.bcgateway.core.api.InfoService import co.nilin.opex.bcgateway.core.model.CurrencyInfo class InfoServiceImpl: InfoService { - override suspend fun countCachedAddresses(): Long { + override suspend fun countReservedAddresses(): Long { TODO() } diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/WalletSyncServiceImpl.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/WalletSyncServiceImpl.kt index 97d80774b..77228ea44 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/WalletSyncServiceImpl.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/WalletSyncServiceImpl.kt @@ -26,9 +26,9 @@ class WalletSyncServiceImpl( deposits.map { deposit -> async(dispatcher) { val uuid = assignedAddressHandler.findUuid(deposit.depositor, deposit.depositorMemo) - if ( uuid != null ) { + if (uuid != null) { val symbol = currencyLoader.findSymbol(deposit.chain!!, deposit.tokenAddress) - walletProxy.transfer(uuid, symbol, deposit.amount) + if (symbol != null) walletProxy.transfer(uuid, symbol, deposit.amount) } } } diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/CachedAddressHandler.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/CachedAddressHandler.kt deleted file mode 100644 index c4271ed2b..000000000 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/CachedAddressHandler.kt +++ /dev/null @@ -1,10 +0,0 @@ -package co.nilin.opex.bcgateway.core.spi - -import co.nilin.opex.bcgateway.core.model.AddressType -import co.nilin.opex.bcgateway.core.model.AssignedAddress -import co.nilin.opex.bcgateway.core.model.CachedAddress - -interface CachedAddressHandler { - suspend fun peekCachedAddress(addressType: AddressType): CachedAddress? - suspend fun remove(cacheAddress: CachedAddress) -} \ No newline at end of file diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/CurrencyLoader.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/CurrencyLoader.kt index 2b105b14f..32aa395f1 100644 --- a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/CurrencyLoader.kt +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/CurrencyLoader.kt @@ -5,6 +5,6 @@ import co.nilin.opex.bcgateway.core.model.CurrencyInfo interface CurrencyLoader { suspend fun fetchCurrencyInfo(symbol: String): CurrencyInfo - suspend fun findSymbol(chain: String, address: String?): String + suspend fun findSymbol(chain: String, address: String?): String? suspend fun findImplementationsWithTokenOnChain(chain: String): List } \ No newline at end of file diff --git a/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ReservedAddressHandler.kt b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ReservedAddressHandler.kt new file mode 100644 index 000000000..67a3c837b --- /dev/null +++ b/BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ReservedAddressHandler.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.bcgateway.core.spi + +import co.nilin.opex.bcgateway.core.model.AddressType +import co.nilin.opex.bcgateway.core.model.ReservedAddress + +interface ReservedAddressHandler { + suspend fun peekReservedAddress(addressType: AddressType): ReservedAddress? + suspend fun remove(reservedAddress: ReservedAddress) +} \ No newline at end of file diff --git a/BlockchainGateway/bc-gateway-core/src/test/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImplUnitTest.kt b/BlockchainGateway/bc-gateway-core/src/test/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImplUnitTest.kt index bd71823f0..be773908d 100644 --- a/BlockchainGateway/bc-gateway-core/src/test/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImplUnitTest.kt +++ b/BlockchainGateway/bc-gateway-core/src/test/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImplUnitTest.kt @@ -2,13 +2,13 @@ package co.nilin.opex.bcgateway.core.service import co.nilin.opex.bcgateway.core.model.AddressType import co.nilin.opex.bcgateway.core.model.AssignedAddress -import co.nilin.opex.bcgateway.core.model.CachedAddress +import co.nilin.opex.bcgateway.core.model.ReservedAddress import co.nilin.opex.bcgateway.core.model.Chain import co.nilin.opex.bcgateway.core.model.Currency import co.nilin.opex.bcgateway.core.model.CurrencyImplementation import co.nilin.opex.bcgateway.core.model.CurrencyInfo import co.nilin.opex.bcgateway.core.spi.AssignedAddressHandler -import co.nilin.opex.bcgateway.core.spi.CachedAddressHandler +import co.nilin.opex.bcgateway.core.spi.ReservedAddressHandler import co.nilin.opex.bcgateway.core.spi.CurrencyLoader import java.lang.RuntimeException import java.math.BigDecimal @@ -16,7 +16,6 @@ import java.util.UUID import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test -import org.junit.jupiter.api.function.Executable import org.mockito.Mock import org.mockito.Mockito import org.mockito.MockitoAnnotations @@ -29,7 +28,7 @@ class AssignAddressServiceImplUnitTest { lateinit var assignedAddressHandler: AssignedAddressHandler @Mock - lateinit var cachedAddressHandler: CachedAddressHandler + lateinit var reservedAddressHandler: ReservedAddressHandler val assignAddressServiceImpl: AssignAddressServiceImpl @@ -43,7 +42,7 @@ class AssignAddressServiceImplUnitTest { init { MockitoAnnotations.openMocks(this) assignAddressServiceImpl = AssignAddressServiceImpl( - currencyLoader, assignedAddressHandler, cachedAddressHandler + currencyLoader, assignedAddressHandler, reservedAddressHandler ) runBlocking { val eth = @@ -67,17 +66,17 @@ class AssignAddressServiceImplUnitTest { } @Test - fun givenCachedAddressAndUserWithNoAssignedAddress_whenAssignAddress_thenCachedAddressAssigned() { + fun givenReservedAddressAndUserWithNoAssignedAddress_whenAssignAddress_thenReservedAddressAssigned() { runBlocking { val user = UUID.randomUUID().toString() Mockito.`when`(assignedAddressHandler.fetchAssignedAddresses(user, listOf(ethAddressType, ethMemoAddressType))).thenReturn( emptyList() ) - Mockito.`when`(cachedAddressHandler.peekCachedAddress(ethAddressType)).thenReturn( - CachedAddress("0x1", null, ethAddressType) + Mockito.`when`(reservedAddressHandler.peekReservedAddress(ethAddressType)).thenReturn( + ReservedAddress("0x1", null, ethAddressType) ) - Mockito.`when`(cachedAddressHandler.peekCachedAddress(ethMemoAddressType)).thenReturn( - CachedAddress("0x2", "Memo", ethMemoAddressType) + Mockito.`when`(reservedAddressHandler.peekReservedAddress(ethMemoAddressType)).thenReturn( + ReservedAddress("0x2", "Memo", ethMemoAddressType) ) val assignedAddress = assignAddressServiceImpl.assignAddress(user, currency) Assertions.assertEquals( @@ -102,13 +101,13 @@ class AssignAddressServiceImplUnitTest { } @Test - fun givenNoCachedAddressAndUserWithNoAssignedAddress_whenAssignAddress_thenExcpetion() { + fun givenNoReservedAddressAndUserWithNoAssignedAddress_whenAssignAddress_thenExcpetion() { runBlocking { val user = UUID.randomUUID().toString() Mockito.`when`(assignedAddressHandler.fetchAssignedAddresses(user, listOf(ethAddressType, ethMemoAddressType))).thenReturn( emptyList() ) - Mockito.`when`(cachedAddressHandler.peekCachedAddress(ethAddressType)).thenReturn(null) + Mockito.`when`(reservedAddressHandler.peekReservedAddress(ethAddressType)).thenReturn(null) Assertions.assertThrows(RuntimeException::class.java) { runBlocking { @@ -119,7 +118,7 @@ class AssignAddressServiceImplUnitTest { } @Test - fun givenCachedAddressAndUserOneAssignedAddress_whenAssignAddress_thenCachedAddressAssigned() { + fun givenReservedAddressAndUserOneAssignedAddress_whenAssignAddress_thenReservedAddressAssigned() { runBlocking { val user = UUID.randomUUID().toString() Mockito.`when`(assignedAddressHandler.fetchAssignedAddresses(user, listOf(ethAddressType, ethMemoAddressType))).thenReturn( @@ -132,11 +131,11 @@ class AssignAddressServiceImplUnitTest { ) ) ) - Mockito.`when`(cachedAddressHandler.peekCachedAddress(ethAddressType)).thenReturn( - CachedAddress("0x1", null, ethAddressType) + Mockito.`when`(reservedAddressHandler.peekReservedAddress(ethAddressType)).thenReturn( + ReservedAddress("0x1", null, ethAddressType) ) - Mockito.`when`(cachedAddressHandler.peekCachedAddress(ethMemoAddressType)).thenReturn( - CachedAddress("0x2", "Memo", ethMemoAddressType) + Mockito.`when`(reservedAddressHandler.peekReservedAddress(ethMemoAddressType)).thenReturn( + ReservedAddress("0x2", "Memo", ethMemoAddressType) ) val assignedAddress = assignAddressServiceImpl.assignAddress(user, currency) Assertions.assertEquals( diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/config/PostgresConfig.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/config/PostgresConfig.kt index 07ca7afa5..0804207c9 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/config/PostgresConfig.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/config/PostgresConfig.kt @@ -13,57 +13,72 @@ class PostgresConfig(db: DatabaseClient) { """ CREATE TABLE IF NOT EXISTS address_types ( id SERIAL PRIMARY KEY, - address_type VARCHAR(72), - address_regex VARCHAR(72), - memo_regex VARCHAR(72) + address_type VARCHAR(72) NOT NULL, + address_regex VARCHAR(72) NOT NULL, + memo_regex VARCHAR(72) NOT NULL ); CREATE TABLE IF NOT EXISTS assigned_addresses ( id SERIAL PRIMARY KEY, - uuid VARCHAR(72) UNIQUE, - address VARCHAR(72), + uuid VARCHAR(72) NOT NULL, + address VARCHAR(72) NOT NULL, memo VARCHAR(72), - addr_type_id numeric, + addr_type_id INTEGER NOT NULL, UNIQUE (address, memo) ); CREATE TABLE IF NOT EXISTS assigned_address_chains ( id SERIAL PRIMARY KEY, - assigned_address_id numeric, - chain VARCHAR(72) + assigned_address_id INTEGER NOT NULL, + chain VARCHAR(72) NOT NULL ); - CREATE TABLE IF NOT EXISTS cached_addresses ( + CREATE TABLE IF NOT EXISTS reserved_addresses ( id SERIAL PRIMARY KEY, - address VARCHAR(72), + address VARCHAR(72) NOT NULL, memo VARCHAR(72), - address_type VARCHAR(72) + address_type VARCHAR(72) NOT NULL, + UNIQUE (address, memo) ); - CREATE TABLE IF NOT EXISTS chain ( + CREATE TABLE IF NOT EXISTS chains ( name VARCHAR(72) PRIMARY KEY ); CREATE TABLE IF NOT EXISTS chain_address_types ( id SERIAL PRIMARY KEY, - chain_name VARCHAR(72), - addr_type_id numeric + chain_name VARCHAR(72) NOT NULL REFERENCES chains (name), + addr_type_id INTEGER NOT NULL REFERENCES address_types (id) ); CREATE TABLE IF NOT EXISTS chain_endpoints ( id SERIAL PRIMARY KEY, - chain_name VARCHAR(72), - endpoint_url VARCHAR(72), + chain_name VARCHAR(72) NOT NULL, + endpoint_url VARCHAR(72) NOT NULL, endpoint_user VARCHAR(72), endpoint_password VARCHAR(72) ); - CREATE TABLE IF NOT EXISTS chain_sync_schedule ( + CREATE TABLE IF NOT EXISTS chain_sync_schedules ( chain VARCHAR(72) PRIMARY KEY, retry_time TIMESTAMP, - delay numeric + delay NUMERIC ); - CREATE TABLE IF NOT EXISTS chain_sync_record ( + CREATE TABLE IF NOT EXISTS chain_sync_records ( chain VARCHAR(72) PRIMARY KEY, - time TIMESTAMP, - endpoint_url VARCHAR(72), - latest_block numeric, - success BOOLEAN, + time TIMESTAMP NOT NULL, + endpoint_url VARCHAR(72) NOT NULL, + latest_block INTEGER NOT NULL, + success BOOLEAN NOT NULL, error VARCHAR(100) ); + CREATE TABLE IF NOT EXISTS currency ( + symbol VARCHAR(72) PRIMARY KEY, + name VARCHAR(72) NOT NULL + ); + CREATE TABLE IF NOT EXISTS currency_implementations ( + symbol VARCHAR(72) PRIMARY KEY, + chain VARCHAR(72) NOT NULL, + token BOOLEAN NOT NULL, + token_address VARCHAR(72), + token_name VARCHAR(72), + withdraw_enabled BOOLEAN NOT NULL, + withdraw_fee NUMERIC NOT NULL, + withdraw_min NUMERIC NOT NULL + ); """ } initDb // initialize the database diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/AssignedAddressRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/AssignedAddressRepository.kt index 96ca13fbf..e6e7e147c 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/AssignedAddressRepository.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/AssignedAddressRepository.kt @@ -6,6 +6,7 @@ import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.query.Param import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.stereotype.Repository +import reactor.core.publisher.Mono @Repository interface AssignedAddressRepository : ReactiveCrudRepository { @@ -13,4 +14,9 @@ interface AssignedAddressRepository : ReactiveCrudRepository ): Flow + + @Query("select * from assigned_addresses where address = :address and (:memo is null or memo = :memo)") + fun findByAddressAndMemo( + @Param("address") address: String, @Param("memo") memo: String? + ): Mono } \ 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/CachedAddressRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/CachedAddressRepository.kt deleted file mode 100644 index f3a30bdeb..000000000 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/CachedAddressRepository.kt +++ /dev/null @@ -1,13 +0,0 @@ -package co.nilin.opex.port.bcgateway.postgres.dao - -import co.nilin.opex.port.bcgateway.postgres.model.AssignedAddressChainModel -import co.nilin.opex.port.bcgateway.postgres.model.CachedAddressModel -import co.nilin.opex.port.bcgateway.postgres.model.ChainModel -import kotlinx.coroutines.flow.Flow -import org.springframework.data.r2dbc.repository.Query -import org.springframework.data.repository.query.Param -import org.springframework.data.repository.reactive.ReactiveCrudRepository - -interface CachedAddressRepository : ReactiveCrudRepository { - -} \ 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/ChainAddressTypeRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainAddressTypeRepository.kt index 5708cb225..2248a9474 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainAddressTypeRepository.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainAddressTypeRepository.kt @@ -2,7 +2,7 @@ package co.nilin.opex.port.bcgateway.postgres.dao import co.nilin.opex.port.bcgateway.postgres.model.ChainAddressTypeModel import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository -interface ChainAddressTypeRepository : ReactiveCrudRepository { - -} \ No newline at end of file +@Repository +interface ChainAddressTypeRepository : ReactiveCrudRepository \ 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/ChainEndpointRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainEndpointRepository.kt index 9c43fe56c..88e5fdc26 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainEndpointRepository.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainEndpointRepository.kt @@ -2,7 +2,7 @@ package co.nilin.opex.port.bcgateway.postgres.dao import co.nilin.opex.port.bcgateway.postgres.model.ChainEndpointModel import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository -interface ChainEndpointRepository : ReactiveCrudRepository { - -} \ No newline at end of file +@Repository +interface ChainEndpointRepository : ReactiveCrudRepository \ 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/ChainRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainRepository.kt index 35de62148..9395b112a 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 @@ -1,12 +1,28 @@ package co.nilin.opex.port.bcgateway.postgres.dao -import co.nilin.opex.port.bcgateway.postgres.model.AssignedAddressChainModel +import co.nilin.opex.port.bcgateway.postgres.model.AddressTypeModel +import co.nilin.opex.port.bcgateway.postgres.model.ChainEndpointModel import co.nilin.opex.port.bcgateway.postgres.model.ChainModel import kotlinx.coroutines.flow.Flow import org.springframework.data.r2dbc.repository.Query -import org.springframework.data.repository.query.Param import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository +@Repository interface ChainRepository : ReactiveCrudRepository { + fun findByName(name: String): Flow + @Query( + """ + select address_types.id, chain_address_types.chain_name, address_types.address_type, address_types.address_regex, address_types.memo_regex + from chain_address_types + join address_types + on address_types.id = chain_address_types.addr_type_id + where chain_name = :name + """ + ) + fun findAddressTypesByName(name: String): Flow + + @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/dao/ChainSyncRecordRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainSyncRecordRepository.kt index 94cb26e68..b3f4ee2b0 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainSyncRecordRepository.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainSyncRecordRepository.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.query.Param import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository -interface ChainSyncRecordRepository : ReactiveCrudRepository { - -} \ No newline at end of file +@Repository +interface ChainSyncRecordRepository : ReactiveCrudRepository \ 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/ChainSyncScheduleRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainSyncScheduleRepository.kt index 7455e08bd..48a7a0252 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainSyncScheduleRepository.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainSyncScheduleRepository.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.query.Param import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository -interface ChainSyncScheduleRepository : ReactiveCrudRepository { - -} \ No newline at end of file +@Repository +interface ChainSyncScheduleRepository : ReactiveCrudRepository \ 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/CurrencyImplementationRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/CurrencyImplementationRepository.kt new file mode 100644 index 000000000..6d00f6a36 --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/CurrencyImplementationRepository.kt @@ -0,0 +1,24 @@ +package co.nilin.opex.port.bcgateway.postgres.dao + +import co.nilin.opex.port.bcgateway.postgres.model.CurrencyImplementationModel +import kotlinx.coroutines.flow.Flow +import org.springframework.data.r2dbc.repository.Query +import org.springframework.data.repository.query.Param +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository +import reactor.core.publisher.Mono + +@Repository +interface CurrencyImplementationRepository : ReactiveCrudRepository { + fun findBySymbol( + symbol: String + ): Flow + + fun findByChain( + chain: String + ): Flow + + fun findByChainAndTokenAddress( + chain: String, tokenAddress: String? + ): Mono +} diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/CurrencyRepository.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/CurrencyRepository.kt new file mode 100644 index 000000000..f44e25b6b --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/CurrencyRepository.kt @@ -0,0 +1,14 @@ +package co.nilin.opex.port.bcgateway.postgres.dao + +import co.nilin.opex.port.bcgateway.postgres.model.CurrencyModel +import kotlinx.coroutines.flow.Flow +import org.springframework.data.r2dbc.repository.Query +import org.springframework.data.repository.query.Param +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository +import reactor.core.publisher.Mono + +@Repository +interface CurrencyRepository : ReactiveCrudRepository { + fun findBySymbol(symbol: String): Mono +} 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 new file mode 100644 index 000000000..a48a80366 --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ReservedAddressRepository.kt @@ -0,0 +1,8 @@ +package co.nilin.opex.port.bcgateway.postgres.dao + +import co.nilin.opex.port.bcgateway.postgres.model.ReservedAddressModel +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository + +@Repository +interface ReservedAddressRepository : ReactiveCrudRepository \ 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/AssignedAddressHandlerImpl.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/AssignedAddressHandlerImpl.kt index 9c42d6695..1e7695999 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/AssignedAddressHandlerImpl.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/AssignedAddressHandlerImpl.kt @@ -7,9 +7,11 @@ import co.nilin.opex.bcgateway.core.spi.ChainLoader import co.nilin.opex.port.bcgateway.postgres.dao.AddressTypeRepository import co.nilin.opex.port.bcgateway.postgres.dao.AssignedAddressChainRepository import co.nilin.opex.port.bcgateway.postgres.dao.AssignedAddressRepository +import co.nilin.opex.port.bcgateway.postgres.model.AssignedAddressModel import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.toList import kotlinx.coroutines.reactive.awaitFirst +import kotlinx.coroutines.reactive.awaitFirstOrNull import org.springframework.stereotype.Service @Service @@ -42,10 +44,18 @@ class AssignedAddressHandlerImpl( } override suspend fun persist(assignedAddress: AssignedAddress) { - TODO("Not yet implemented") + assignedAddressRepository.save( + AssignedAddressModel( + null, + assignedAddress.uuid, + assignedAddress.address, + assignedAddress.memo, + assignedAddress.type.id + ) + ).awaitFirst() } override suspend fun findUuid(address: String, memo: String?): String? { - TODO("Not yet implemented") + return assignedAddressRepository.findByAddressAndMemo(address, memo).awaitFirstOrNull()?.uuid } } \ 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/CachedAddressHandlerImpl.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/CachedAddressHandlerImpl.kt deleted file mode 100644 index 52e868cfe..000000000 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/CachedAddressHandlerImpl.kt +++ /dev/null @@ -1,15 +0,0 @@ -package co.nilin.opex.port.bcgateway.postgres.impl - -import co.nilin.opex.bcgateway.core.model.AddressType -import co.nilin.opex.bcgateway.core.model.CachedAddress -import co.nilin.opex.bcgateway.core.spi.CachedAddressHandler - -class CachedAddressHandlerImpl: CachedAddressHandler { - override suspend fun peekCachedAddress(addressType: AddressType): CachedAddress? { - TODO("Not yet implemented") - } - - override suspend fun remove(cacheAddress: CachedAddress) { - TODO("Not yet implemented") - } -} \ 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/CurrencyLoaderImpl.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/CurrencyLoaderImpl.kt index 0d519f77b..118329469 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/CurrencyLoaderImpl.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/CurrencyLoaderImpl.kt @@ -1,19 +1,62 @@ package co.nilin.opex.port.bcgateway.postgres.impl -import co.nilin.opex.bcgateway.core.model.CurrencyImplementation -import co.nilin.opex.bcgateway.core.model.CurrencyInfo +import co.nilin.opex.bcgateway.core.model.* import co.nilin.opex.bcgateway.core.spi.CurrencyLoader +import co.nilin.opex.port.bcgateway.postgres.dao.ChainRepository +import co.nilin.opex.port.bcgateway.postgres.dao.CurrencyImplementationRepository +import co.nilin.opex.port.bcgateway.postgres.dao.CurrencyRepository +import co.nilin.opex.port.bcgateway.postgres.model.CurrencyImplementationModel +import co.nilin.opex.port.bcgateway.postgres.model.CurrencyModel +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.reactive.awaitFirstOrNull +import kotlinx.coroutines.reactive.awaitSingle +import kotlinx.coroutines.reactive.awaitSingleOrNull +import org.springframework.stereotype.Component -class CurrencyLoaderImpl: CurrencyLoader { +@Component +class CurrencyLoaderImpl( + private val chainRepository: ChainRepository, + private val currencyRepository: CurrencyRepository, + private val currencyImplementationRepository: CurrencyImplementationRepository +) : CurrencyLoader { override suspend fun fetchCurrencyInfo(symbol: String): CurrencyInfo { - TODO("Not yet implemented") + val currencyDao = currencyRepository.findBySymbol(symbol).awaitSingleOrNull() + if (currencyDao === null) return CurrencyInfo(Currency("", symbol), emptyList()) + val currencyImplDao = currencyImplementationRepository.findBySymbol(symbol) + val currency = Currency(currencyDao.symbol, currencyDao.name) + val implementations = currencyImplDao.map { projectCurrencyImplementation(it, currencyDao) } + return CurrencyInfo(currency, implementations.toList()) } - override suspend fun findSymbol(chain: String, address: String?): String { - TODO("Not yet implemented") + override suspend fun findSymbol(chain: String, address: String?): String? { + return currencyImplementationRepository.findByChainAndTokenAddress(chain, address) + .awaitFirstOrNull()?.symbol } override suspend fun findImplementationsWithTokenOnChain(chain: String): List { - TODO("Not yet implemented") + return currencyImplementationRepository.findByChain(chain).map { projectCurrencyImplementation(it) }.toList() } -} \ No newline at end of file + + private suspend fun projectCurrencyImplementation( + implDao: CurrencyImplementationModel, + currencyDao: CurrencyModel? = null + ): CurrencyImplementation { + val addressTypesDao = chainRepository.findAddressTypesByName(implDao.chain) + val addressTypes = addressTypesDao.map { AddressType(it.id!!, it.type, it.addressRegex, it.memoRegex) } + val endpointsDao = chainRepository.findEndpointsByName(implDao.chain) + val endpoints = endpointsDao.map { Endpoint(it.url) } + val currencyDaoVal = currencyDao ?: currencyRepository.findBySymbol(implDao.symbol).awaitSingle() + val currency = Currency(currencyDaoVal.symbol, currencyDaoVal.name) + return CurrencyImplementation( + currency, + Chain(implDao.chain, addressTypes.toList(), endpoints.toList()), + implDao.token, + implDao.tokenAddress, + implDao.tokenName, + implDao.withdrawEnabled, + implDao.withdrawFee, + implDao.withdrawMin + ) + } +} 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 new file mode 100644 index 000000000..ed2e0e547 --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ReservedAddressHandlerImpl.kt @@ -0,0 +1,17 @@ +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 org.springframework.stereotype.Component + +@Component +class ReservedAddressHandlerImpl: ReservedAddressHandler { + override suspend fun peekReservedAddress(addressType: AddressType): ReservedAddress? { + TODO("Not yet implemented") + } + + override suspend fun remove(reservedAddress: ReservedAddress) { + TODO("Not yet implemented") + } +} \ 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/model/ChainModel.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/ChainModel.kt index 11c79f3e0..fb91ee878 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/ChainModel.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/ChainModel.kt @@ -4,7 +4,7 @@ import org.springframework.data.annotation.Id import org.springframework.data.relational.core.mapping.Column import org.springframework.data.relational.core.mapping.Table -@Table("chain") +@Table("chains") data class ChainModel(@Id val name: String) @Table("chain_address_types") diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CurrencyImplementationModel.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CurrencyImplementationModel.kt new file mode 100644 index 000000000..eeaaa6f59 --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CurrencyImplementationModel.kt @@ -0,0 +1,20 @@ +package co.nilin.opex.port.bcgateway.postgres.model + + +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Column +import org.springframework.data.relational.core.mapping.Table +import java.math.BigDecimal + +@Table("currency_implementations") +class CurrencyImplementationModel( + @Id val id: Long?, + @Column("symbol") val symbol: String, + @Column("chain") val chain: String, + @Column("token") val token: Boolean, + @Column("token_address") val tokenAddress: String?, + @Column("token_name") val tokenName: String?, + @Column("withdraw_enabled") val withdrawEnabled: Boolean, + @Column("withdraw_fee") val withdrawFee: BigDecimal, + @Column("withdraw_min") val withdrawMin: BigDecimal, +) diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CurrencyModel.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CurrencyModel.kt new file mode 100644 index 000000000..354398e25 --- /dev/null +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CurrencyModel.kt @@ -0,0 +1,12 @@ +package co.nilin.opex.port.bcgateway.postgres.model + + +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Column +import org.springframework.data.relational.core.mapping.Table + +@Table("currency") +class CurrencyModel( + @Id @Column("symbol") val symbol: String, + @Column("name") val name: String +) diff --git a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CachedAddressModel.kt b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/ReservedAddressModel.kt similarity index 81% rename from BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CachedAddressModel.kt rename to BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/ReservedAddressModel.kt index fbb698b1b..fb2d37358 100644 --- a/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/CachedAddressModel.kt +++ b/BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/model/ReservedAddressModel.kt @@ -3,7 +3,7 @@ package co.nilin.opex.port.bcgateway.postgres.model import org.springframework.data.relational.core.mapping.Column import org.springframework.data.relational.core.mapping.Table -@Table("cached_addresses") -data class CachedAddressModel( +@Table("reserved_addresses") +data class ReservedAddressModel( val id: Long?, val address: String, val memo: String?, @Column("address_type") val type: Long ) \ No newline at end of file diff --git a/Deployment/docker-compose.yml b/Deployment/docker-compose.yml index 0dda34600..e10c538b7 100644 --- a/Deployment/docker-compose.yml +++ b/Deployment/docker-compose.yml @@ -45,16 +45,12 @@ services: condition: on-failure redis: image: "redis:alpine" - command: redis-server - ports: - "127.0.0.1:6379:6379" - volumes: - $PWD/runtime/redis-data:/var/lib/redis - $PWD/runtime/redis.conf:/usr/local/etc/redis/redis.conf - environment: - REDIS_REPLICATION_MODE=master networks: @@ -131,6 +127,21 @@ services: deploy: restart_policy: condition: on-failure + postgres-bc-gateway: + image: "postgres" + ports: + - 127.0.0.1:5438:5432 + environment: + - POSTGRES_USER=opex + - POSTGRES_PASSWORD=hiopex + - POSTGRES_DB=opex_bc_gateway + volumes: + - $PWD/runtime/bc-gateway-data:/var/lib/postgresql/data/ + networks: + - opex + deploy: + restart_policy: + condition: on-failure accountant: container_name: accountant build: @@ -310,6 +321,32 @@ services: - api networks: - opex + bc-gateway: + container_name: bc-gateway + build: + context: ../BlockchainGateway/bc-gateway-app + dockerfile: Dockerfile + ports: + - 127.0.0.1:8095:8095 + - 127.0.0.1:1051:1044 + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 + - SPRING_PROFILES_ACTIVE=docker + - KAFKA_IP_PORT=kafka:9092 + - REDIS_HOST=redis + - CONSUL_HOST=consul + - DB_IP_PORT=postgres-bc-gateway + networks: + - opex + depends_on: + - zookeeper + - kafka + - redis + - consul + - postgres-bc-gateway + deploy: + restart_policy: + condition: on-failure networks: opex: driver: bridge \ No newline at end of file