diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/ChainInfo.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/ChainInfo.kt index e6c0540a6..f1c5805dd 100644 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/ChainInfo.kt +++ b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/ChainInfo.kt @@ -3,6 +3,7 @@ package co.nilin.opex.api.core.inout data class ChainInfo( val name: String, val addressTypes: String?, - val externalChainScannerUrl: String? = null, - val addressRegex: String? = null + val addressRegex: String? = null, + val transactionScannerUrl: String? = null, + val addressScannerUrl: String? = null ) \ No newline at end of file diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/controller/AdminController.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/controller/AdminController.kt index b774fe834..d538ece5f 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/controller/AdminController.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/controller/AdminController.kt @@ -28,8 +28,9 @@ class AdminController( ChainResponse( c.name, c.addressTypes.map { it.type }.getOrNull(0), - c.externalChinScannerUrl, - c.addressTypes.map { it.addressRegex }.getOrNull(0) + c.addressTypes.map { it.addressRegex }.getOrNull(0), + c.transactionScannerUrl, + c.addressScannerUrl, ) } } diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/controller/CryptoCurrencyController.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/controller/CryptoCurrencyController.kt index 7c2c6d07f..2cd2f2152 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/controller/CryptoCurrencyController.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/controller/CryptoCurrencyController.kt @@ -8,8 +8,6 @@ import co.nilin.opex.bcgateway.core.model.FetchGateways import co.nilin.opex.bcgateway.core.model.WithdrawData import co.nilin.opex.bcgateway.core.spi.ChainLoader import co.nilin.opex.bcgateway.core.spi.CryptoCurrencyHandlerV2 -import kotlinx.coroutines.currentCoroutineContext -import kotlinx.coroutines.reactor.ReactorContext import org.springframework.web.bind.annotation.* @RestController @@ -78,9 +76,10 @@ class CryptoCurrencyController( ChainResponse( c.name, c.addressTypes.map { it.type }.getOrNull(0), - c.externalChinScannerUrl, - c.addressTypes.map { it.addressRegex }.getOrNull(0) - ) + c.addressTypes.map { it.addressRegex }.getOrNull(0), + c.transactionScannerUrl, + c.addressScannerUrl, + ) } } diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/dto/AddChainRequest.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/dto/AddChainRequest.kt index ef148cdb3..49e6135d5 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/dto/AddChainRequest.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/dto/AddChainRequest.kt @@ -3,9 +3,10 @@ package co.nilin.opex.bcgateway.app.dto data class AddChainRequest( val name: String?, val addressType: String?, - val scannerEndpoint: String?, val scheduleDelaySeconds: Int, val scheduleErrorDelaySeconds: Int, + val transactionScannerUrl: String? = null, + val addressScannerUrl: String? = null ) { fun isValid(): Boolean { return !name.isNullOrEmpty() && !addressType.isNullOrEmpty() && scheduleDelaySeconds > 0 && scheduleErrorDelaySeconds > 0 diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/dto/ChainResponse.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/dto/ChainResponse.kt index fbb860f7b..e061aa263 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/dto/ChainResponse.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/dto/ChainResponse.kt @@ -3,6 +3,7 @@ package co.nilin.opex.bcgateway.app.dto data class ChainResponse( val name: String, val addressTypes: String?, - val externalChainScannerUrl: String? = null, - val addressRegex: String? = null + val addressRegex: String? = null, + val transactionScannerUrl: String? = null, + val addressScannerUrl: String?= null, ) diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/service/AdminService.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/service/AdminService.kt index f9ad972c0..756695d4a 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/service/AdminService.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/service/AdminService.kt @@ -30,7 +30,7 @@ class AdminService( @Transactional suspend fun addChain(body: AddChainRequest) { - chainLoader.addChain(body.name!!, body.addressType!!) + chainLoader.addChain(body.name!!, body.addressType!!, body.transactionScannerUrl, body.addressScannerUrl) } suspend fun addAddressType(name: String, addressRegex: String, memoRegex: String?) { diff --git a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Chain.kt b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Chain.kt index 1b6c98000..c48ae4522 100644 --- a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Chain.kt +++ b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/model/Chain.kt @@ -3,4 +3,6 @@ package co.nilin.opex.bcgateway.core.model data class Chain( val name: String, val addressTypes: List, - val externalChinScannerUrl: String? = null) + val transactionScannerUrl: String? = null, + val addressScannerUrl: String? = null +) diff --git a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainLoader.kt b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainLoader.kt index 6c3f6bd4c..57b900372 100644 --- a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainLoader.kt +++ b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainLoader.kt @@ -4,7 +4,12 @@ import co.nilin.opex.bcgateway.core.model.Chain interface ChainLoader { - suspend fun addChain(name: String, addressType: String): Chain + suspend fun addChain( + name: String, + addressType: String, + transactionScannerUrl: String?, + addressScannerUrl: String? + ): Chain suspend fun fetchAllChains(): List diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/dao/ChainRepository.kt b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/dao/ChainRepository.kt index 32194b3ee..6f7e904ab 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/dao/ChainRepository.kt +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/dao/ChainRepository.kt @@ -11,8 +11,12 @@ import reactor.core.publisher.Mono @Repository interface ChainRepository : ReactiveCrudRepository { - @Query("insert into chains values (:name) on conflict do nothing") - fun insert(name: String): Mono + @Query("insert into chains values (:name,:transaction_scanner_url,:address_scanner_url) on conflict do nothing") + fun insert( + name: String, + transactionScannerUrl: String?, + addressScannerUrl: String? + ): Mono fun findByName(name: String): Mono? diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/impl/ChainHandler.kt b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/impl/ChainHandler.kt index c14bb6c08..6006172a9 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/impl/ChainHandler.kt +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/impl/ChainHandler.kt @@ -21,7 +21,12 @@ class ChainHandler( private val chainAddressRepository: ChainAddressTypeRepository ) : ChainLoader { - override suspend fun addChain(name: String, addressType: String): Chain { + override suspend fun addChain( + name: String, + addressType: String, + transactionScannerUrl: String?, + addressScannerUrl: String? + ): Chain { val chain = chainRepository.findByName(name)?.awaitFirstOrNull() if (chain != null) throw OpexError.BadRequest.exception() @@ -29,10 +34,10 @@ class ChainHandler( val type = addressTypeRepository.findByType(addressType).awaitFirstOrNull() ?: throw OpexError.InvalidAddressType.exception() - chainRepository.insert(name).awaitFirstOrNull() + chainRepository.insert(name, transactionScannerUrl, addressScannerUrl).awaitFirstOrNull() val model = chainRepository.findByName(name)?.awaitFirstOrElse { throw OpexError.BadRequest.exception() } chainAddressRepository.save(ChainAddressTypeModel(null, model!!.name, type.id!!)).awaitFirstOrNull() - return Chain(model.name, emptyList()) + return Chain(model.name, emptyList(), transactionScannerUrl, addressScannerUrl) } override suspend fun fetchAllChains(): List { @@ -44,7 +49,7 @@ class ChainHandler( .map { AddressType(it.id!!, it.type, it.addressRegex, it.memoRegex) } .toList() - Chain(c.name, addressTypes, c.externalChainScannerUrl) + Chain(c.name, addressTypes, c.transactionScannerUrl, c.addressScannerUrl) } } @@ -52,7 +57,7 @@ class ChainHandler( val chainDao = chainRepository.findByName(chain)?.awaitFirstOrElse { throw OpexError.ChainNotFound.exception() } val addressTypes = chainRepository.findAddressTypesByName(chain) .map { AddressType(it.id!!, it.type, it.addressRegex, it.memoRegex) }.toList() - return Chain(chainDao!!.name, addressTypes) + return Chain(chainDao!!.name, addressTypes, chainDao.transactionScannerUrl, chainDao.addressScannerUrl) } } diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/model/ChainModel.kt b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/model/ChainModel.kt index 9c3d8c4b8..77c4806b1 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/model/ChainModel.kt +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/model/ChainModel.kt @@ -4,4 +4,8 @@ import org.springframework.data.annotation.Id import org.springframework.data.relational.core.mapping.Table @Table("chains") -data class ChainModel(@Id val name: String, val externalChainScannerUrl: String?) +data class ChainModel( + @Id val name: String, + val transactionScannerUrl: String?, + val addressScannerUrl: String? +) diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/db/migration/V6__add_chain_scanner_urls.sql b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/db/migration/V6__add_chain_scanner_urls.sql new file mode 100644 index 000000000..1c08e26ad --- /dev/null +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/db/migration/V6__add_chain_scanner_urls.sql @@ -0,0 +1,4 @@ +Alter table chains drop column external_chain_scanner_url; + +Alter table chains add column transaction_scanner_url VARCHAR(150); +Alter table chains add column address_scanner_url VARCHAR(150);