Skip to content

Commit aa2cfde

Browse files
authored
Merge pull request #74 from opexdev/feature/1-MVP
Implement reserved addresses and chain proxy
2 parents e7d452f + 9b8605f commit aa2cfde

File tree

12 files changed

+198
-13
lines changed

12 files changed

+198
-13
lines changed

BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Address.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ package co.nilin.opex.bcgateway.core.model
22

33
data class AddressType(val id: Long, val type: String, val addressRegex: String, val memoRegex: String)
44
data class ReservedAddress(val address: String, val memo: String?, val type: AddressType)
5-
data class AssignedAddress(val uuid: String, val address: String, val memo: String?, val type: AddressType, val chains: MutableList<Chain> ){
5+
data class AssignedAddress(
6+
val uuid: String,
7+
val address: String,
8+
val memo: String?,
9+
val type: AddressType,
10+
val chains: MutableList<Chain>
11+
) {
612
override fun equals(other: Any?): Boolean {
713
if (this === other) return true
814
if (javaClass != other?.javaClass) return false
@@ -24,4 +30,4 @@ data class AssignedAddress(val uuid: String, val address: String, val memo: Stri
2430
result = 31 * result + type.hashCode()
2531
return result
2632
}
27-
}
33+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package co.nilin.opex.bcgateway.core.spi
22

33
interface ChainEndpointProxyFinder {
4-
suspend fun findChainEndpointProxy(chainName: String):ChainEndpointProxy
5-
}
4+
suspend fun findChainEndpointProxy(chainName: String): ChainEndpointProxy
5+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
34+
!/.mvn/
35+
36+
.DS_Store
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.4.4</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<groupId>co.nilin.opex.external</groupId>
14+
<artifactId>bc-chain-proxy</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
<kotlin.version>1.4.31</kotlin.version>
20+
<bc-gateway.version>${version}</bc-gateway.version>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter</artifactId>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>io.projectreactor.kotlin</groupId>
31+
<artifactId>reactor-kotlin-extensions</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.jetbrains.kotlin</groupId>
35+
<artifactId>kotlin-reflect</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.jetbrains.kotlin</groupId>
39+
<artifactId>kotlin-stdlib-jdk8</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.jetbrains.kotlinx</groupId>
43+
<artifactId>kotlinx-coroutines-reactor</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.jetbrains.kotlinx</groupId>
47+
<artifactId>kotlinx-coroutines-core</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>co.nilin.opex.external</groupId>
51+
<artifactId>bc-gateway-core</artifactId>
52+
<version>${bc-gateway.version}</version>
53+
</dependency>
54+
</dependencies>
55+
56+
<build>
57+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
58+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.jetbrains.kotlin</groupId>
62+
<artifactId>kotlin-maven-plugin</artifactId>
63+
<configuration>
64+
<args>
65+
<arg>-Xjsr305=strict</arg>
66+
</args>
67+
<compilerPlugins>
68+
<plugin>spring</plugin>
69+
</compilerPlugins>
70+
</configuration>
71+
<dependencies>
72+
<dependency>
73+
<groupId>org.jetbrains.kotlin</groupId>
74+
<artifactId>kotlin-maven-allopen</artifactId>
75+
<version>${kotlin.version}</version>
76+
</dependency>
77+
</dependencies>
78+
</plugin>
79+
</plugins>
80+
</build>
81+
82+
<repositories>
83+
<repository>
84+
<id>spring-milestones</id>
85+
<name>Spring Milestones</name>
86+
<url>https://repo.spring.io/milestone</url>
87+
</repository>
88+
</repositories>
89+
90+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package co.nilin.opex.port.bcgateway.chainproxy.impl
2+
3+
import co.nilin.opex.bcgateway.core.model.ChainSyncRecord
4+
import co.nilin.opex.bcgateway.core.model.Endpoint
5+
import co.nilin.opex.bcgateway.core.spi.ChainEndpointProxy
6+
import org.springframework.stereotype.Component
7+
8+
class ChainEndpointProxyImpl(private val endpoints: List<Endpoint>) : ChainEndpointProxy {
9+
override suspend fun syncTransfers(filter: ChainEndpointProxy.DepositFilter): ChainSyncRecord {
10+
TODO("Not yet implemented")
11+
}
12+
}

BlockchainGateway/bc-gateway-ports/bc-persister-postgres/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@
6767
<artifactId>reactor-test</artifactId>
6868
<scope>test</scope>
6969
</dependency>
70-
</dependencies>
70+
<dependency>
71+
<groupId>co.nilin.opex.external</groupId>
72+
<artifactId>bc-chain-proxy</artifactId>
73+
<version>1.0-SNAPSHOT</version>
74+
<scope>compile</scope>
75+
</dependency>
76+
</dependencies>
7177

7278
<build>
7379
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>

BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/dao/ChainRepository.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import kotlinx.coroutines.flow.Flow
77
import org.springframework.data.r2dbc.repository.Query
88
import org.springframework.data.repository.reactive.ReactiveCrudRepository
99
import org.springframework.stereotype.Repository
10+
import reactor.core.publisher.Mono
1011

1112
@Repository
1213
interface ChainRepository : ReactiveCrudRepository<ChainModel, String> {
13-
fun findByName(name: String): Flow<ChainModel>
14+
fun findByName(name: String): Mono<ChainModel>
1415

1516
@Query(
1617
"""
@@ -25,4 +26,4 @@ interface ChainRepository : ReactiveCrudRepository<ChainModel, String> {
2526

2627
@Query("select * from chain_endpoints where chain_name = :name")
2728
fun findEndpointsByName(name: String): Flow<ChainEndpointModel>
28-
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
package co.nilin.opex.port.bcgateway.postgres.dao
22

33
import co.nilin.opex.port.bcgateway.postgres.model.ReservedAddressModel
4+
import org.springframework.data.r2dbc.repository.Modifying
5+
import org.springframework.data.r2dbc.repository.Query
46
import org.springframework.data.repository.reactive.ReactiveCrudRepository
57
import org.springframework.stereotype.Repository
8+
import reactor.core.publisher.Mono
69

710
@Repository
8-
interface ReservedAddressRepository : ReactiveCrudRepository<ReservedAddressModel, Long>
11+
interface ReservedAddressRepository : ReactiveCrudRepository<ReservedAddressModel, Long> {
12+
@Query("select * from reserved_addresses where address_type = :addressType order by id DESC")
13+
fun peekFirstAdded(addressType: Long): Mono<ReservedAddressModel>
14+
15+
@Modifying
16+
@Query("delete from reserved_addresses where address = :address and (memo is null or memo = :memo)")
17+
fun remove(address: String, memo: String?): Mono<Int>
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package co.nilin.opex.port.bcgateway.postgres.impl
2+
3+
import co.nilin.opex.bcgateway.core.model.Endpoint
4+
import co.nilin.opex.bcgateway.core.spi.ChainEndpointProxy
5+
import co.nilin.opex.bcgateway.core.spi.ChainEndpointProxyFinder
6+
import co.nilin.opex.port.bcgateway.chainproxy.impl.ChainEndpointProxyImpl
7+
import co.nilin.opex.port.bcgateway.postgres.dao.ChainRepository
8+
import kotlinx.coroutines.flow.map
9+
import kotlinx.coroutines.flow.toList
10+
import org.springframework.stereotype.Component
11+
12+
@Component
13+
class ChainEndpointProxyFinderImpl(private val chainRepository: ChainRepository) : ChainEndpointProxyFinder {
14+
override suspend fun findChainEndpointProxy(chainName: String): ChainEndpointProxy {
15+
val endpoints = chainRepository.findEndpointsByName(chainName).map { Endpoint(it.url) }.toList()
16+
return ChainEndpointProxyImpl(endpoints)
17+
}
18+
}

BlockchainGateway/bc-gateway-ports/bc-persister-postgres/src/main/kotlin/co/nilin/opex/port/bcgateway/postgres/impl/ReservedAddressHandlerImpl.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ package co.nilin.opex.port.bcgateway.postgres.impl
33
import co.nilin.opex.bcgateway.core.model.AddressType
44
import co.nilin.opex.bcgateway.core.model.ReservedAddress
55
import co.nilin.opex.bcgateway.core.spi.ReservedAddressHandler
6+
import co.nilin.opex.port.bcgateway.postgres.dao.ReservedAddressRepository
7+
import kotlinx.coroutines.reactive.awaitFirst
8+
import kotlinx.coroutines.reactive.awaitFirstOrNull
69
import org.springframework.stereotype.Component
710

811
@Component
9-
class ReservedAddressHandlerImpl: ReservedAddressHandler {
12+
class ReservedAddressHandlerImpl(private val reservedAddressRepository: ReservedAddressRepository) :
13+
ReservedAddressHandler {
1014
override suspend fun peekReservedAddress(addressType: AddressType): ReservedAddress? {
11-
TODO("Not yet implemented")
15+
return reservedAddressRepository.peekFirstAdded(addressType.id)
16+
.map { ReservedAddress(it.address, it.memo, addressType) }.awaitFirstOrNull()
1217
}
1318

1419
override suspend fun remove(reservedAddress: ReservedAddress) {
15-
TODO("Not yet implemented")
20+
reservedAddressRepository.remove(reservedAddress.address, reservedAddress.memo).awaitFirst()
1621
}
17-
}
22+
}

0 commit comments

Comments
 (0)