diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/WithdrawHistoryResponse.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/WithdrawHistoryResponse.kt index bb9e75daf..3d0d6607a 100644 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/WithdrawHistoryResponse.kt +++ b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/WithdrawHistoryResponse.kt @@ -6,10 +6,11 @@ data class WithdrawHistoryResponse( val withdrawId: Long?, val uuid: String, val amount: BigDecimal, + val currency: String, val acceptedFee: BigDecimal, val appliedFee: BigDecimal?, val destAmount: BigDecimal?, - val destCurrency: String?, + val destSymbol: String?, val destAddress: String?, val destNetwork: String?, var destNote: String?, diff --git a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/WalletController.kt b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/WalletController.kt index c299e91ca..49da873a1 100644 --- a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/WalletController.kt +++ b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/WalletController.kt @@ -127,7 +127,7 @@ class WalletController( LocalDateTime.ofInstant(Instant.ofEpochMilli(it.createDate), ZoneId.systemDefault()) .toString() .replace("T", " "), - it.destCurrency ?: "", + it.destSymbol ?: "", it.withdrawId?.toString() ?: "", "", it.destNetwork ?: "", diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/WithdrawController.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/WithdrawController.kt index 86204bda4..fbd8a10cd 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/WithdrawController.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/WithdrawController.kt @@ -64,20 +64,28 @@ class WithdrawController(private val withdrawService: WithdrawService) { ) suspend fun requestWithdraw( principal: Principal, - @PathVariable("symbol") symbol: String, + @PathVariable("currency") currency: String, @PathVariable("amount") amount: BigDecimal, @RequestParam("description", required = false) description: String?, @RequestParam("transferRef", required = false) transferRef: String?, @RequestParam("fee") fee: BigDecimal, - @RequestParam("destCurrency") destCurrency: String, + @RequestParam("destSymbol") destSymbol: String, @RequestParam("destAddress") destAddress: String, @RequestParam("destNetwork") destNetwork: String, @RequestParam("destNote", required = false) destNote: String?, ): WithdrawResult { return withdrawService.requestWithdraw( WithdrawCommand( - principal.name, symbol, - amount, description, transferRef, destCurrency, destAddress, destNetwork, destNote, fee + principal.name, + currency, + amount, + description, + transferRef, + destSymbol, + destAddress, + destNetwork, + destNote, + fee ) ) } @@ -99,10 +107,11 @@ class WithdrawController(private val withdrawService: WithdrawService) { it.withdrawId, it.ownerUuid, it.amount, + it.currency, it.acceptedFee, it.appliedFee, it.destAmount, - it.destCurrency, + it.destSymbol, it.destAddress, it.destNetwork, it.destNote, diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/WithdrawHistoryResponse.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/WithdrawHistoryResponse.kt index f01016723..4db260698 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/WithdrawHistoryResponse.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/WithdrawHistoryResponse.kt @@ -6,10 +6,11 @@ data class WithdrawHistoryResponse( val withdrawId: Long? = null, val uuid: String, val amount: BigDecimal, + val currency: String, val acceptedFee: BigDecimal, val appliedFee: BigDecimal?, val destAmount: BigDecimal?, - val destCurrency: String?, + val destSymbol: String?, val destAddress: String?, val destNetwork: String?, var destNote: String?, diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/WithdrawCommand.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/WithdrawCommand.kt index 50d0ffd4c..10c213f78 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/WithdrawCommand.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/WithdrawCommand.kt @@ -4,11 +4,11 @@ import java.math.BigDecimal class WithdrawCommand( val uuid: String, - val symbol: String, + val currency: String, val amount: BigDecimal, val description: String?, val transferRef: String?, - val destCurrency: String, + val destSymbol: String, val destAddress: String, val destNetwork: String, val destNote: String?, diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/WithdrawResponse.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/WithdrawResponse.kt index 9eb60c3da..6a7f3f6a6 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/WithdrawResponse.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/WithdrawResponse.kt @@ -15,7 +15,7 @@ class WithdrawResponse( val appliedFee: BigDecimal?, val amount: BigDecimal?, val destAmount: BigDecimal?, - val destCurrency: String?, + val destSymbol: String?, val destAddress: String?, val destNetwork: String?, var destNote: String?, diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/model/Withdraw.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/model/Withdraw.kt index 76a2eb507..e99a3eadc 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/model/Withdraw.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/model/Withdraw.kt @@ -6,6 +6,7 @@ import java.time.LocalDateTime data class Withdraw( val withdrawId: Long? = null, val ownerUuid: String, + val currency: String, val wallet: Long, val amount: BigDecimal, val requestTransaction: String, @@ -13,7 +14,7 @@ data class Withdraw( val acceptedFee: BigDecimal, val appliedFee: BigDecimal?, val destAmount: BigDecimal?, - val destCurrency: String?, + val destSymbol: String?, val destAddress: String?, val destNetwork: String?, var destNote: String?, diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt index a3d333580..ed92c5380 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt @@ -26,7 +26,7 @@ class WithdrawService( suspend fun requestWithdraw( withdrawCommand: WithdrawCommand ): WithdrawResult { - val currency = currencyService.getCurrency(withdrawCommand.symbol) ?: throw IllegalArgumentException() + val currency = currencyService.getCurrency(withdrawCommand.currency) ?: throw IllegalArgumentException() val owner = walletOwnerManager.findWalletOwner(withdrawCommand.uuid) ?: throw IllegalArgumentException() val sourceWallet = walletManager.findWalletByOwnerAndCurrencyAndType(owner, "main", currency) @@ -51,12 +51,23 @@ class WithdrawService( ) val withdraw = withdrawPersister.persist( Withdraw( - null, owner.uuid, receiverWallet.id!!, withdrawCommand.amount, - transferResultDetailed.tx, null, - withdrawCommand.acceptedFee, null, - null, withdrawCommand.destCurrency, - withdrawCommand.destAddress, withdrawCommand.destNetwork, - withdrawCommand.destNote, null, null, "CREATED" + null, + owner.uuid, + currency.symbol, + receiverWallet.id!!, + withdrawCommand.amount, + transferResultDetailed.tx, + null, + withdrawCommand.acceptedFee, + null, + null, + withdrawCommand.destSymbol, + withdrawCommand.destAddress, + withdrawCommand.destNetwork, + withdrawCommand.destNote, + null, + null, + "CREATED" ) ) return WithdrawResult(withdraw.withdrawId!!, withdraw.status) @@ -97,6 +108,7 @@ class WithdrawService( Withdraw( withdraw.withdrawId, withdraw.ownerUuid, + withdraw.currency, withdraw.wallet, withdraw.amount, withdraw.requestTransaction, @@ -104,7 +116,7 @@ class WithdrawService( withdraw.acceptedFee, withdraw.appliedFee, withdraw.amount.subtract(acceptCommand.appliedFee), - withdraw.destCurrency, + withdraw.destSymbol, withdraw.destAddress, withdraw.destNetwork, withdraw.destNote ?: ("" + "-----------" + (acceptCommand.destNote ?: "")), @@ -150,6 +162,7 @@ class WithdrawService( Withdraw( withdraw.withdrawId, withdraw.ownerUuid, + withdraw.currency, withdraw.wallet, withdraw.amount, withdraw.requestTransaction, @@ -157,7 +170,7 @@ class WithdrawService( withdraw.acceptedFee, null, null, - withdraw.destCurrency, + withdraw.destSymbol, withdraw.destAddress, withdraw.destNetwork, withdraw.destNote ?: ("" + "-----------" + (rejectCommand.destNote ?: "")), diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/WithdrawRepository.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/WithdrawRepository.kt index 03d7faea3..1e8acc4fa 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/WithdrawRepository.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/WithdrawRepository.kt @@ -108,7 +108,7 @@ interface WithdrawRepository : ReactiveCrudRepository { """ select * from withdraws where uuid = :uuid - and dest_currency = :currency + and currency = :currency and create_date > :startTime and create_date <= :endTime limit :limit diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WithdrawPersisterImpl.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WithdrawPersisterImpl.kt index 0499d80df..341d4aa74 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WithdrawPersisterImpl.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WithdrawPersisterImpl.kt @@ -97,6 +97,7 @@ class WithdrawPersisterImpl( WithdrawModel( withdraw.withdrawId, withdraw.ownerUuid, + withdraw.currency, withdraw.wallet, withdraw.amount, withdraw.requestTransaction, @@ -104,7 +105,7 @@ class WithdrawPersisterImpl( withdraw.acceptedFee, withdraw.appliedFee, withdraw.destAmount, - withdraw.destCurrency, + withdraw.destSymbol, withdraw.destNetwork, withdraw.destAddress, withdraw.destNote, @@ -157,7 +158,7 @@ class WithdrawPersisterImpl( appliedFee, amount, destAmount, - destCurrency, + destSymbol, destAddress, destNetwork, destNote, @@ -173,6 +174,7 @@ class WithdrawPersisterImpl( return Withdraw( id, ownerUuid, + currency, wallet, amount, requestTransaction, @@ -180,7 +182,7 @@ class WithdrawPersisterImpl( acceptedFee, appliedFee, destAmount, - destCurrency, + destSymbol, destAddress, destNetwork, destNote, diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/WithdrawModel.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/WithdrawModel.kt index 8dab4a5eb..3b3e5a8ad 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/WithdrawModel.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/WithdrawModel.kt @@ -10,6 +10,7 @@ import java.time.LocalDateTime data class WithdrawModel( @Id var id: Long?, @Column("uuid") val ownerUuid: String, + @Column("currency") val currency: String, @Column("wallet") val wallet: Long, @Column("amount") val amount: BigDecimal, @Column("req_transaction_id") val requestTransaction: String, @@ -17,7 +18,7 @@ data class WithdrawModel( @Column("accepted_fee") val acceptedFee: BigDecimal, @Column("applied_fee") val appliedFee: BigDecimal?, @Column("dest_amount") val destAmount: BigDecimal?, - @Column("dest_currency") val destCurrency: String?, + @Column("dest_symbol") val destSymbol: String?, @Column("dest_network") val destNetwork: String?, @Column("dest_address") val destAddress: String?, @Column("dest_notes") var destNote: String?, diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql index f88eba345..e01ad593a 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql @@ -65,12 +65,13 @@ CREATE TABLE IF NOT EXISTS withdraws uuid VARCHAR(36) NOT NULL, req_transaction_id VARCHAR(20) NOT NULL UNIQUE, final_transaction_id VARCHAR(20) UNIQUE, - wallet INTEGER REFERENCES wallet (id), - amount DECIMAL NOT NULL, - accepted_fee DECIMAL, + currency VARCHAR(20) NOT NULL REFERENCES currency (symbol), + wallet INTEGER NOT NULL REFERENCES wallet (id), + amount DECIMAL NOT NULL, + accepted_fee DECIMAL NOT NULL, applied_fee DECIMAL, dest_amount DECIMAL, - dest_currency VARCHAR(20) REFERENCES currency (symbol), + dest_symbol VARCHAR(20), dest_network VARCHAR(20), dest_address VARCHAR(80), dest_notes TEXT, @@ -78,6 +79,6 @@ CREATE TABLE IF NOT EXISTS withdraws description TEXT, status_reason TEXT, status VARCHAR(20), - create_date TIMESTAMP NOT NULL, + create_date TIMESTAMP NOT NULL, accept_date TIMESTAMP );