commit 5654142d459afc960708de4bf28c8c38f9be5cf6
parent 545bce3b826a9980cb1991b9f07964f3707b5413
Author: Antoine A <>
Date: Wed, 22 Nov 2023 11:37:31 +0000
Fix conversion API
Diffstat:
2 files changed, 6 insertions(+), 25 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/ConversionApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/ConversionApi.kt
@@ -35,16 +35,7 @@ fun Routing.conversionApi(db: Database, ctx: BankConfig) = conditional(ctx.allow
regional_currency_specification = ctx.regionalCurrencySpec,
fiat_currency = ctx.fiatCurrency!!,
fiat_currency_specification = ctx.fiatCurrencySpec!!,
- cashin_ratio = ctx.conversionInfo!!.cashin_ratio,
- cashin_fee = ctx.conversionInfo.cashin_fee,
- cashin_tiny_amount = ctx.conversionInfo.cashin_tiny_amount,
- cashin_rounding_mode = ctx.conversionInfo.cashin_rounding_mode,
- cashin_min_amount = ctx.conversionInfo.cashin_min_amount,
- cashout_ratio = ctx.conversionInfo.cashout_ratio,
- cashout_fee = ctx.conversionInfo.cashout_fee,
- cashout_tiny_amount = ctx.conversionInfo.cashout_tiny_amount,
- cashout_rounding_mode = ctx.conversionInfo.cashout_rounding_mode,
- cashout_min_amount = ctx.conversionInfo.cashout_min_amount
+ conversion_info = ctx.conversionInfo!!
)
)
}
@@ -73,10 +64,8 @@ fun Routing.conversionApi(db: Database, ctx: BankConfig) = conditional(ctx.allow
get("/conversion-info/cashin-rate") {
val params = RateParams.extract(call.request.queryParameters)
- params.debit?.let { ctx.checkFiatCurrency(it) }
- params.credit?.let { ctx.checkRegionalCurrency(it) }
-
if (params.debit != null) {
+ ctx.checkFiatCurrency(params.debit)
val credit = db.conversion.toCashin(params.debit) ?:
throw conflict(
"${params.debit} is too small to be converted",
@@ -84,9 +73,10 @@ fun Routing.conversionApi(db: Database, ctx: BankConfig) = conditional(ctx.allow
)
call.respond(ConversionResponse(params.debit, credit))
} else {
- val debit = db.conversion.fromCashin(params.credit!!) ?:
+ ctx.checkRegionalCurrency(params.credit!!)
+ val debit = db.conversion.fromCashin(params.credit) ?:
throw conflict(
- "${params.debit} is too small to be converted",
+ "${params.credit} is too small to be converted",
TalerErrorCode.BANK_BAD_CONVERSION
)
call.respond(ConversionResponse(debit, params.credit))
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
@@ -229,16 +229,7 @@ data class ConversionConfig(
val regional_currency_specification: CurrencySpecification,
val fiat_currency: String,
val fiat_currency_specification: CurrencySpecification,
- val cashin_ratio: DecimalNumber,
- val cashin_fee: TalerAmount,
- val cashin_tiny_amount: TalerAmount,
- val cashin_rounding_mode: RoundingMode,
- val cashin_min_amount: TalerAmount,
- val cashout_ratio: DecimalNumber,
- val cashout_fee: TalerAmount,
- val cashout_tiny_amount: TalerAmount,
- val cashout_rounding_mode: RoundingMode,
- val cashout_min_amount: TalerAmount,
+ val conversion_info: ConversionInfo
) {
val name: String = "taler-conversion-info"
val version: String = "0:0:0"