Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Chain> ){
data class AssignedAddress(
val uuid: String,
val address: String,
val memo: String?,
val type: AddressType,
val chains: MutableList<Chain>
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
Expand All @@ -24,4 +30,4 @@ data class AssignedAddress(val uuid: String, val address: String, val memo: Stri
result = 31 * result + type.hashCode()
return result
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package co.nilin.opex.bcgateway.core.spi

interface ChainEndpointProxyFinder {
suspend fun findChainEndpointProxy(chainName: String):ChainEndpointProxy
}
suspend fun findChainEndpointProxy(chainName: String): ChainEndpointProxy
}
36 changes: 36 additions & 0 deletions BlockchainGateway/bc-gateway-ports/bc-chain-proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions BlockchainGateway/bc-gateway-ports/bc-chain-proxy/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>co.nilin.opex.external</groupId>
<artifactId>bc-chain-proxy</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<java.version>1.8</java.version>
<kotlin.version>1.4.31</kotlin.version>
<bc-gateway.version>${version}</bc-gateway.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>io.projectreactor.kotlin</groupId>
<artifactId>reactor-kotlin-extensions</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-reactor</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
</dependency>
<dependency>
<groupId>co.nilin.opex.external</groupId>
<artifactId>bc-gateway-core</artifactId>
<version>${bc-gateway.version}</version>
</dependency>
</dependencies>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
@@ -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<Endpoint>) : ChainEndpointProxy {
override suspend fun syncTransfers(filter: ChainEndpointProxy.DepositFilter): ChainSyncRecord {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>co.nilin.opex.external</groupId>
<artifactId>bc-chain-proxy</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChainModel, String> {
fun findByName(name: String): Flow<ChainModel>
fun findByName(name: String): Mono<ChainModel>

@Query(
"""
Expand All @@ -25,4 +26,4 @@ interface ChainRepository : ReactiveCrudRepository<ChainModel, String> {

@Query("select * from chain_endpoints where chain_name = :name")
fun findEndpointsByName(name: String): Flow<ChainEndpointModel>
}
}
Original file line number Diff line number Diff line change
@@ -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<ReservedAddressModel, Long>
interface ReservedAddressRepository : ReactiveCrudRepository<ReservedAddressModel, Long> {
@Query("select * from reserved_addresses where address_type = :addressType order by id DESC")
fun peekFirstAdded(addressType: Long): Mono<ReservedAddressModel>

@Modifying
@Query("delete from reserved_addresses where address = :address and (memo is null or memo = :memo)")
fun remove(address: String, memo: String?): Mono<Int>
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
1 change: 1 addition & 0 deletions BlockchainGateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<module>bc-gateway-core</module>
<module>bc-gateway-app</module>
<module>bc-gateway-ports/bc-persister-postgres</module>
<module>bc-gateway-ports/bc-chain-proxy</module>
</modules>
</project>
4 changes: 2 additions & 2 deletions Deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -349,4 +349,4 @@ services:
condition: on-failure
networks:
opex:
driver: bridge
driver: bridge