Skip to content

Commit ec82866

Browse files
Close #25, Complete assign address service (#57)
* Complete AssignAddressHandler implementation * Rename cached address to reserved address * Add unique constraint to reserved_addresses table * Fix unique constraint in assigned addresses * Improve sql initiate script * Fix persist method * Fix uuid unique constraint in assigned addresses * Add currency models * Add currency repositories * Fix currency implementation * Implement currency loader * Change currency table primary key to symbol * Add currency tables * Format Chain.kt * Fix symbol nullability in WalletSyncServiceImpl.kt * Add blockchain module to docker-compose * Fix blockchain module port configs * Fix bc-gateway docker config * Fix bc-gateway database name in docker config * Add missing @repository attributes * Add bc-gateway-postgres dependency to bc-gateway-app * Update docker-compose config * Fix sql scripts * Fix blockchain gateway port * Pluralize db names * Fix chain model table names * Fix numeric types in database * Fix currency loader * Update chain repository * Add id to chain repository fetch method * Add chain model data to currency loader * Refactor currency loader * Apply DRY to currency loader * Fix null currency issue in currency loader * Handle not found currency
1 parent 930e642 commit ec82866

34 files changed

Lines changed: 550 additions & 352 deletions

BlockchainGateway/bc-gateway-app/pom.xml

Lines changed: 223 additions & 218 deletions
Large diffs are not rendered by default.

BlockchainGateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/AppConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class AppConfig {
2121
fun assignAddressService(
2222
currencyLoader: CurrencyLoader,
2323
assignedAddressHandler: AssignedAddressHandler,
24-
cachedAddressHandler: CachedAddressHandler
24+
reservedAddressHandler: ReservedAddressHandler
2525
): AssignAddressService {
26-
return AssignAddressServiceImpl(currencyLoader, assignedAddressHandler, cachedAddressHandler)
26+
return AssignAddressServiceImpl(currencyLoader, assignedAddressHandler, reservedAddressHandler)
2727
}
2828

2929
@Bean

BlockchainGateway/bc-gateway-app/src/main/resources/application-docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
server.port: 8091
1+
server.port: 8095
22
spring:
33
application:
44
name: opex-bc-gateway

BlockchainGateway/bc-gateway-app/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
server.port: 8091
1+
server.port: 8095
22
spring:
33
application:
44
name: opex-bc-gateway

BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/api/InfoService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package co.nilin.opex.bcgateway.core.api
33
import co.nilin.opex.bcgateway.core.model.CurrencyInfo
44

55
interface InfoService {
6-
suspend fun countCachedAddresses(): Long
6+
suspend fun countReservedAddresses(): Long
77
suspend fun getCurrencyInfo(): CurrencyInfo
88
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package co.nilin.opex.bcgateway.core.model
22

33
data class AddressType(val id: Long, val type: String, val addressRegex: String, val memoRegex: String)
4-
data class CachedAddress(val address: String, val memo: String?, val type: AddressType)
4+
data class ReservedAddress(val address: String, val memo: String?, val type: AddressType)
55
data class AssignedAddress(val uuid: String, val address: String, val memo: String?, val type: AddressType, val chains: MutableList<Chain> ){
66
override fun equals(other: Any?): Boolean {
77
if (this === other) return true

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import java.time.LocalDateTime
66
data class Endpoint(val url: String)
77
data class Chain(val name: String, val addressTypes: List<AddressType>, val endpoints: List<Endpoint>)
88
data class ChainSyncSchedule(val chainName: String, val retryTime: LocalDateTime, val delay: Long)
9-
data class ChainSyncRecord(val chainName: String
10-
, val time: LocalDateTime
11-
, val endpoint: Endpoint
12-
, val latestBlock: Long?
13-
, val success: Boolean
14-
, val error: String?
15-
, val records: List<Deposit>
9+
data class ChainSyncRecord(
10+
val chainName: String,
11+
val time: LocalDateTime,
12+
val endpoint: Endpoint,
13+
val latestBlock: Long?,
14+
val success: Boolean,
15+
val error: String?,
16+
val records: List<Deposit>
1617
)
1718

BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/AssignAddressServiceImpl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import co.nilin.opex.bcgateway.core.model.AssignedAddress
66
import co.nilin.opex.bcgateway.core.model.Chain
77
import co.nilin.opex.bcgateway.core.model.Currency
88
import co.nilin.opex.bcgateway.core.spi.AssignedAddressHandler
9-
import co.nilin.opex.bcgateway.core.spi.CachedAddressHandler
9+
import co.nilin.opex.bcgateway.core.spi.ReservedAddressHandler
1010
import co.nilin.opex.bcgateway.core.spi.CurrencyLoader
1111
import java.lang.RuntimeException
1212

1313
class AssignAddressServiceImpl(
1414
val currencyLoader: CurrencyLoader,
1515
val assignedAddressHandler: AssignedAddressHandler,
16-
val cachedAddressHandler: CachedAddressHandler
16+
val reservedAddressHandler: ReservedAddressHandler
1717
) : AssignAddressService {
1818

1919
override suspend fun assignAddress(user: String, currency: Currency): List<AssignedAddress> {
@@ -42,19 +42,19 @@ class AssignAddressServiceImpl(
4242
}
4343
result.add(assigned)
4444
} else {
45-
val cachedAddress = cachedAddressHandler.peekCachedAddress(addressType)
46-
if (cachedAddress != null) {
45+
val reservedAddress = reservedAddressHandler.peekReservedAddress(addressType)
46+
if (reservedAddress != null) {
4747
val newAssigned = AssignedAddress(
4848
user,
49-
cachedAddress.address,
50-
cachedAddress.memo,
49+
reservedAddress.address,
50+
reservedAddress.memo,
5151
addressType,
5252
chainAddressTypeMap.get(addressType)!!
5353
)
54-
cachedAddressHandler.remove(cachedAddress)
54+
reservedAddressHandler.remove(reservedAddress)
5555
result.add(newAssigned)
5656
} else
57-
throw RuntimeException("No cached address available for $addressType")
57+
throw RuntimeException("No reserved address available for $addressType")
5858

5959
}
6060
}

BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/InfoServiceImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import co.nilin.opex.bcgateway.core.api.InfoService
44
import co.nilin.opex.bcgateway.core.model.CurrencyInfo
55

66
class InfoServiceImpl: InfoService {
7-
override suspend fun countCachedAddresses(): Long {
7+
override suspend fun countReservedAddresses(): Long {
88
TODO()
99
}
1010

BlockchainGateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/WalletSyncServiceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class WalletSyncServiceImpl(
2626
deposits.map { deposit ->
2727
async(dispatcher) {
2828
val uuid = assignedAddressHandler.findUuid(deposit.depositor, deposit.depositorMemo)
29-
if ( uuid != null ) {
29+
if (uuid != null) {
3030
val symbol = currencyLoader.findSymbol(deposit.chain!!, deposit.tokenAddress)
31-
walletProxy.transfer(uuid, symbol, deposit.amount)
31+
if (symbol != null) walletProxy.transfer(uuid, symbol, deposit.amount)
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)