libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit f23ba0cc186099898dbbca0bca44bd6130312f95
parent e6ee5db0b3de1ffe2a3aebbdb46023610005aaa8
Author: MS <ms@taler.net>
Date:   Thu, 22 Dec 2022 15:48:51 +0100

Circuit API: GET /config.

Diffstat:
Anexus/src/test/kotlin/CircuitApiTest.kt | 21+++++++++++++++++++++
Asandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt | 33+++++++++++++++++++++++++++++++++
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 6+++++-
3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/nexus/src/test/kotlin/CircuitApiTest.kt b/nexus/src/test/kotlin/CircuitApiTest.kt @@ -0,0 +1,20 @@ +import io.ktor.client.features.* +import io.ktor.client.features.get +import io.ktor.client.request.* +import io.ktor.server.testing.* +import kotlinx.coroutines.runBlocking +import org.junit.Test +import tech.libeufin.sandbox.sandboxApp + +class CircuitApiTest { + // Get /config + @Test + fun config() { + withTestApplication(sandboxApp) { + runBlocking { + val r: String = client.get("/demobanks/default/circuit-api/config") + println(r) + } + } + } +} +\ No newline at end of file diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt @@ -0,0 +1,32 @@ +package tech.libeufin.sandbox + +import io.ktor.application.* +import io.ktor.response.* +import io.ktor.routing.* + +// CIRCUIT API TYPES + +// Configuration response: +class ConfigResp( + val name: String = "circuit", + val version: String = SANDBOX_VERSION, + val ratios_and_fees: RatioAndFees +) + +// After fixing #7527, the values held by this +// type must be read from the configuration. +class RatioAndFees( + val buy_at_ratio: Float = 1F, + val sell_at_ratio: Float = 0.05F, + val buy_in_fee: Float = 0F, + val sell_out_fee: Float = 0F +) + +fun circuitApi(circuitRoute: Route) { + circuitRoute.get("/config") { + call.respond(ConfigResp( + ratios_and_fees = RatioAndFees() + )) + return@get + } +} +\ No newline at end of file diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -66,6 +66,7 @@ import javax.xml.bind.JAXBContext import kotlin.system.exitProcess val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox") +const val SANDBOX_VERSION = "0:0:0" const val SANDBOX_DB_ENV_VAR_NAME = "LIBEUFIN_SANDBOX_DB_CONNECTION" private val adminPassword: String? = System.getenv("LIBEUFIN_SANDBOX_ADMIN_PASSWORD") var WITH_AUTH = true // Needed by helpers too, hence not making it private. @@ -1136,7 +1137,7 @@ val sandboxApp: Application.() -> Unit = { val demobank = ensureDemobank(call) call.respond(SandboxConfig( name = "taler-bank-integration", - version = "0:0:0", + version = SANDBOX_VERSION, currency = demobank.currency )) return@get @@ -1204,6 +1205,9 @@ val sandboxApp: Application.() -> Unit = { return@get } } + route("/circuit-api") { + circuitApi(this) + } // Talk to Web UI. route("/access-api") { post("/accounts/{account_name}/transactions") {