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 @@ -5,9 +5,9 @@ import org.springframework.boot.runApplication
import org.springframework.context.annotation.ComponentScan

@SpringBootApplication
@ComponentScan("co.nilin.mixchange")
class WalletApp
@ComponentScan("co.nilin.opex")
class BCGatewayApp

fun main(args: Array<String>) {
runApplication<WalletApp>(*args)
runApplication<BCGatewayApp>(*args)
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,73 @@
package co.nilin.mixchange.port.order.kafka.config

package co.nilin.opex.port.bcgateway.postgres.config

import org.springframework.context.annotation.Configuration
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories
import org.springframework.r2dbc.core.DatabaseClient


@Configuration
@EnableR2dbcRepositories(basePackages = ["co.nilin.mixchange"])
@EnableR2dbcRepositories(basePackages = ["co.nilin.opex"])
class PostgresConfig(db: DatabaseClient) {

init {
val initDb = db.sql {
"""
CREATE TABLE IF NOT EXISTS address_types (
id SERIAL PRIMARY KEY,
address_type VARCHAR(72),
address_regex VARCHAR(72),
memo_regex VARCHAR(72)
);
CREATE TABLE IF NOT EXISTS assigned_addresses (
id SERIAL PRIMARY KEY,
uuid VARCHAR(72) UNIQUE,
address VARCHAR(72),
memo VARCHAR(72),
addr_type_id numeric,
UNIQUE (address, memo)
);
CREATE TABLE IF NOT EXISTS assigned_address_chains (
id SERIAL PRIMARY KEY,
assigned_address_id numeric,
chain VARCHAR(72)
);
CREATE TABLE IF NOT EXISTS cached_addresses (
id SERIAL PRIMARY KEY,
address VARCHAR(72),
memo VARCHAR(72),
address_type VARCHAR(72)
);
CREATE TABLE IF NOT EXISTS chain (
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
);
CREATE TABLE IF NOT EXISTS chain_endpoints (
id SERIAL PRIMARY KEY,
chain_name VARCHAR(72),
endpoint_url VARCHAR(72),
endpoint_user VARCHAR(72),
endpoint_password VARCHAR(72)
);
CREATE TABLE IF NOT EXISTS chain_sync_schedule (
chain VARCHAR(72) PRIMARY KEY,
retry_time TIMESTAMP,
delay numeric
);
CREATE TABLE IF NOT EXISTS chain_sync_record (
chain VARCHAR(72) PRIMARY KEY,
time TIMESTAMP,
endpoint_url VARCHAR(72),
latest_block numeric,
success BOOLEAN,
error VARCHAR(100)
);
"""
}
initDb // initialize the database
.then()
.subscribe() // execute
.then()
.subscribe() // execute
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository

@Repository
interface AddressTypeRepository: ReactiveCrudRepository<AddressTypeModel, Long>
interface AddressTypeRepository : ReactiveCrudRepository<AddressTypeModel, Long>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository

@Repository
interface AssignedAddressChainRepository: ReactiveCrudRepository<AssignedAddressChainModel, Long> {
interface AssignedAddressChainRepository : ReactiveCrudRepository<AssignedAddressChainModel, Long> {
@Query("select * from assigned_address_chains where assigned_address_id = :assignedAddress")
fun findByAssignedAddress(@Param("assignedAddress") type: Long): Flow<AssignedAddressChainModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository

@Repository
interface AssignedAddressRepository: ReactiveCrudRepository<AssignedAddressModel, Long> {
interface AssignedAddressRepository : ReactiveCrudRepository<AssignedAddressModel, Long> {
@Query("select * from assigned_addresses where uuid = :uuid and addr_type_id in (:addressTypes)")
fun findByUuidAndAddressType(@Param("uuid") uuid: String
, @Param("addressTypes") types: List<Long>): Flow<AssignedAddressModel>
fun findByUuidAndAddressType(
@Param("uuid") uuid: String, @Param("addressTypes") types: List<Long>
): Flow<AssignedAddressModel>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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<CachedAddressModel, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.nilin.opex.port.bcgateway.postgres.dao

import co.nilin.opex.port.bcgateway.postgres.model.ChainAddressTypeModel
import org.springframework.data.repository.reactive.ReactiveCrudRepository

interface ChainAddressTypeRepository : ReactiveCrudRepository<ChainAddressTypeModel, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.nilin.opex.port.bcgateway.postgres.dao

import co.nilin.opex.port.bcgateway.postgres.model.ChainEndpointModel
import org.springframework.data.repository.reactive.ReactiveCrudRepository

interface ChainEndpointRepository : ReactiveCrudRepository<ChainEndpointModel, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import org.springframework.data.r2dbc.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.data.repository.reactive.ReactiveCrudRepository

interface ChainRepository: ReactiveCrudRepository<ChainModel, Long> {
interface ChainRepository : ReactiveCrudRepository<ChainModel, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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.ChainModel
import co.nilin.opex.port.bcgateway.postgres.model.SyncRecord
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 ChainSyncRecordRepository : ReactiveCrudRepository<SyncRecord, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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.ChainModel
import co.nilin.opex.port.bcgateway.postgres.model.SyncScheduleModel
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 ChainSyncScheduleRepository : ReactiveCrudRepository<SyncScheduleModel, String> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import org.springframework.data.relational.core.mapping.Table

@Table("address_types")
data class AddressTypeModel(
val id: Long?
, @Column("address_type") val type: String
, @Column("address_regex") val addressRegex: String
, @Column("memo_regex") val memoRegex: String
val id: Long?,
@Column("address_type") val type: String,
@Column("address_regex") val addressRegex: String,
@Column("memo_regex") val memoRegex: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.Table

@Table("cached_addresses")
data class CachedAddressModel(val address: String
, val memo: String?
, @Column("address_type") val type: Long
data class CachedAddressModel(
val id: Long?, val address: String, val memo: String?, @Column("address_type") val type: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import org.springframework.data.relational.core.mapping.Table
data class ChainModel(@Id val name: String)

@Table("chain_address_types")
data class ChainAddressTypeModel(@Id val id: Long?
, @Column("chain_name") val chainName: String
, @Column("addr_type_id") val addressTypeId: Long)
data class ChainAddressTypeModel(
@Id val id: Long?, @Column("chain_name") val chainName: String, @Column("addr_type_id") val addressTypeId: Long
)

@Table("chain_endpoints")
data class ChainEndpointModel(@Id val id: Long?
, @Column("chain_name") val chainName: String
, @Column("endpoint_url") val url: String
, @Column("endpoint_user") val user: String
, @Column("endpoint_password") val password: String
)
data class ChainEndpointModel(
@Id val id: Long?,
@Column("chain_name") val chainName: String,
@Column("endpoint_url") val url: String,
@Column("endpoint_user") val user: String,
@Column("endpoint_password") val password: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ data class SyncScheduleModel(
)

@Table("chain_sync_record")
data class SyncRecord(@Id @Column("chain") val chain: String
, val time: LocalDateTime
, @Column("endpoint_url") val endpointUrl: String
, @Column("latest_block") val latestBlock: Long?
, val success: Boolean
, val error: String?)
data class SyncRecord(
@Id @Column("chain") val chain: String,
val time: LocalDateTime,
@Column("endpoint_url") val endpointUrl: String,
@Column("latest_block") val latestBlock: Long?,
val success: Boolean,
val error: String?
)