summaryrefslogtreecommitdiff
path: root/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
blob: 16519c46d5103d0e25b2c8584005655218846ac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
/*
 * This file is part of LibEuFin.
 * Copyright (C) 2020 Taler Systems S.A.
 *
 * LibEuFin is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation; either version 3, or
 * (at your option) any later version.
 *
 * LibEuFin is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
 * Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with LibEuFin; see the file COPYING.  If not, see
 * <http://www.gnu.org/licenses/>
 */

package tech.libeufin.nexus

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.application.ApplicationCall
import io.ktor.application.call
import io.ktor.client.HttpClient
import io.ktor.client.request.post
import io.ktor.client.statement.*
import io.ktor.content.TextContent
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType
import io.ktor.request.receive
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.routing.Route
import io.ktor.routing.get
import io.ktor.routing.post
import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
import tech.libeufin.nexus.bankaccount.addPaymentInitiation
import tech.libeufin.nexus.iso20022.*
import tech.libeufin.nexus.server.*
import tech.libeufin.util.*
import kotlin.math.abs
import kotlin.math.min

/** Payment initiating data structures: one endpoint "$BASE_URL/transfer". */
data class TalerTransferRequest(
    val request_uid: String,
    val amount: String,
    val exchange_base_url: String,
    val wtid: String,
    val credit_account: String
)

data class TalerTransferResponse(
    /**
     * Point in time when the nexus put the payment instruction into the database.
     */
    val timestamp: GnunetTimestamp,
    val row_id: Long
)

/**
 * History accounting data structures
 */
data class TalerIncomingBankTransaction(
    val row_id: Long,
    val date: GnunetTimestamp, // timestamp
    val amount: String,
    val credit_account: String, // payto form,
    val debit_account: String,
    val reserve_pub: String
)

data class TalerIncomingHistory(
    var incoming_transactions: MutableList<TalerIncomingBankTransaction> = mutableListOf()
)

data class TalerOutgoingBankTransaction(
    val row_id: Long,
    val date: GnunetTimestamp, // timestamp
    val amount: String,
    val credit_account: String, // payto form,
    val debit_account: String,
    val wtid: String,
    val exchange_base_url: String
)

data class TalerOutgoingHistory(
    var outgoing_transactions: MutableList<TalerOutgoingBankTransaction> = mutableListOf()
)

/** Test APIs' data structures. */
data class TalerAdminAddIncoming(
    val amount: String,
    val reserve_pub: String,
    /**
     * This account is the one giving money to the exchange.  It doesn't
     * have to be 'created' as it might (and normally is) simply be a payto://
     * address pointing to a bank account hosted in a different financial
     * institution.
     */
    val debit_account: String
)

data class GnunetTimestamp(
    val t_ms: Long
)

data class TalerAddIncomingResponse(
    val timestamp: GnunetTimestamp,
    val row_id: Long
)


/** Sort query results in descending order for negative deltas, and ascending otherwise.  */
fun <T : Entity<Long>> SizedIterable<T>.orderTaler(delta: Int): List<T> {
    return if (delta < 0) {
        this.sortedByDescending { it.id }
    } else {
        this.sortedBy { it.id }
    }
}

/**
 * Build an IBAN payto URI.
 */
fun buildIbanPaytoUri(
    iban: String, bic: String, name: String, direction: String
): String {
    val nameParam = if (direction == "DBIT") "sender-name" else "receiver-name"
    return "payto://iban/$bic/$iban?$nameParam=$name"
}

/** Builds the comparison operator for history entries based on the sign of 'delta'  */
fun getComparisonOperator(delta: Int, start: Long, table: IdTable<Long>): Op<Boolean> {
    return if (delta < 0) {
        Expression.build {
            table.id less start
        }
    } else {
        Expression.build {
            table.id greater start
        }
    }
}

fun expectLong(param: String?): Long {
    if (param == null) {
        throw EbicsProtocolError(HttpStatusCode.BadRequest, "'$param' is not Long")
    }
    return try {
        param.toLong()
    } catch (e: Exception) {
        throw EbicsProtocolError(HttpStatusCode.BadRequest, "'$param' is not Long")
    }
}

/** Helper handling 'start' being optional and its dependence on 'delta'.  */
fun handleStartArgument(start: String?, delta: Int): Long {
    if (start == null) {
        if (delta >= 0)
            return -1
        return Long.MAX_VALUE
    }
    return expectLong(start)
}

/**
 * The Taler layer cannot rely on the ktor-internal JSON-converter/responder,
 * because this one adds a "charset" extra information in the Content-Type header
 * that makes the GNUnet JSON parser unhappy.
 *
 * The workaround is to explicitly convert the 'data class'-object into a JSON
 * string (what this function does), and use the simpler respondText method.
 */
fun customConverter(body: Any): String {
    return jacksonObjectMapper().writeValueAsString(body)
}

/**
 * Tries to extract a valid reserve public key from the raw subject line
 */
fun extractReservePubFromSubject(rawSubject: String): String? {
    val re = "\\b[a-z0-9A-Z]{52}\\b".toRegex()
    val result = re.find(rawSubject.replace("[\n]+".toRegex(), "")) ?: return null
    return result.value.toUpperCase()
}

private fun getTalerFacadeState(fcid: String): TalerFacadeStateEntity {
    val facade = FacadeEntity.find { FacadesTable.facadeName eq fcid }.firstOrNull() ?: throw NexusError(
        HttpStatusCode.NotFound,
        "Could not find facade '${fcid}'"
    )
    return TalerFacadeStateEntity.find {
        TalerFacadeStateTable.facade eq facade.id.value
    }.firstOrNull() ?: throw NexusError(
        HttpStatusCode.NotFound,
        "Could not find any state for facade: $fcid"
    )
}

private fun getTalerFacadeBankAccount(fcid: String): NexusBankAccountEntity {
    val facadeState = getTalerFacadeState(fcid)
    return NexusBankAccountEntity.findByName(facadeState.bankAccount) ?: throw NexusError(
        HttpStatusCode.NotFound,
        "The facade: ${fcid} doesn't manage bank account: ${facadeState.bankAccount}"
    )
}

/**
 * Handle a Taler Wire Gateway /transfer request.
 */
private suspend fun talerTransfer(call: ApplicationCall) {
    val transferRequest = call.receive<TalerTransferRequest>()
    val amountObj = parseAmount(transferRequest.amount)
    // FIXME: Right now we only parse the credit_account, should we also validate that it matches our account info?
    parsePayto(transferRequest.credit_account)
    val facadeId = expectNonNull(call.parameters["fcid"])
    val opaqueRowId = transaction {
        // FIXME: re-enable authentication (https://bugs.gnunet.org/view.php?id=6703)
        // val exchangeUser = authenticateRequest(call.request)
        call.request.requirePermission(PermissionQuery("facade", facadeId, "facade.talerWireGateway.transfer"))
        val facade = FacadeEntity.find { FacadesTable.facadeName eq facadeId }.firstOrNull() ?: throw NexusError(
            HttpStatusCode.NotFound,
            "Could not find facade '${facadeId}'"
        )
        val creditorData = parsePayto(transferRequest.credit_account)
        /** Checking the UID has the desired characteristics */
        TalerRequestedPaymentEntity.find {
            TalerRequestedPaymentsTable.requestUid eq transferRequest.request_uid
        }.forEach {
            if (
                (it.amount != transferRequest.amount) or
                (it.creditAccount != transferRequest.exchange_base_url) or
                (it.wtid != transferRequest.wtid)
            ) {
                throw NexusError(
                    HttpStatusCode.Conflict,
                    "This uid (${transferRequest.request_uid}) belongs to a different payment already"
                )
            }
        }
        val exchangeBankAccount = getTalerFacadeBankAccount(facadeId)
        val pain001 = addPaymentInitiation(
            Pain001Data(
                creditorIban = creditorData.iban,
                creditorBic = creditorData.bic,
                creditorName = creditorData.name ?: throw NexusError(
                    HttpStatusCode.BadRequest, "Payto did not mention account owner"
                ),
                subject = transferRequest.wtid,
                sum = amountObj.amount,
                currency = amountObj.currency
            ),
            exchangeBankAccount
        )
        logger.debug("Taler requests payment: ${transferRequest.wtid}")
        val row = TalerRequestedPaymentEntity.new {
            this.facade = facade
            preparedPayment = pain001 // not really used/needed, just here to silence warnings
            exchangeBaseUrl = transferRequest.exchange_base_url
            requestUid = transferRequest.request_uid
            amount = transferRequest.amount
            wtid = transferRequest.wtid
            creditAccount = transferRequest.credit_account
        }
        row.id.value
    }
    return call.respond(
        TextContent(
            customConverter(
                TalerTransferResponse(
                    /**
                     * Normally should point to the next round where the background
                     * routine will send new PAIN.001 data to the bank; work in progress..
                     */
                    timestamp = roundTimestamp(GnunetTimestamp(System.currentTimeMillis())),
                    row_id = opaqueRowId
                )
            ),
            ContentType.Application.Json
        )
    )
}

fun roundTimestamp(t: GnunetTimestamp): GnunetTimestamp {
    return GnunetTimestamp(t.t_ms - (t.t_ms % 1000))
}

private fun ingestOneIncomingTransaction(payment: NexusBankTransactionEntity, txDtls: TransactionDetails) {
    val subject = txDtls.unstructuredRemittanceInformation
    val debtorName = txDtls.debtor?.name
    if (debtorName == null) {
        logger.warn("empty debtor name")
        return
    }
    val debtorAcct = txDtls.debtorAccount
    if (debtorAcct == null) {
        // FIXME: Report payment, we can't even send it back
        logger.warn("empty debtor account")
        return
    }
    val debtorIban = debtorAcct.iban
    if (debtorIban == null) {
        // FIXME: Report payment, we can't even send it back
        logger.warn("non-iban debtor account")
        return
    }
    val debtorAgent = txDtls.debtorAgent
    if (debtorAgent == null) {
        // FIXME: Report payment, we can't even send it back
        logger.warn("missing debtor agent")
        return
    }
    if (debtorAgent.bic == null) {
        logger.warn("Not allowing transactions missing the BIC.  IBAN and name: ${debtorIban}, $debtorName")
        return
    }
    val reservePub = extractReservePubFromSubject(subject)
    if (reservePub == null){
        logger.warn("could not find reserve pub in remittance information")
        TalerInvalidIncomingPaymentEntity.new {
            this.payment = payment
            timestampMs = System.currentTimeMillis()
        }
        // FIXME: send back!
        return
    }

    if (!CryptoUtil.checkValidEddsaPublicKey(reservePub)) {
        // FIXME: send back!
        logger.warn("invalid public key")
        TalerInvalidIncomingPaymentEntity.new {
            this.payment = payment
            timestampMs = System.currentTimeMillis()
        }
        logger.warn("Invalid public key found")
        // FIXME: send back!
        return
    }
    TalerIncomingPaymentEntity.new {
        this.payment = payment
        reservePublicKey = reservePub
        timestampMs = System.currentTimeMillis()
        debtorPaytoUri = buildIbanPaytoUri(
            debtorIban, debtorAgent.bic, debtorName, "DBIT"
        )
    }
    return
}

fun maybePrepareRefunds(bankAccount: NexusBankAccountEntity, lastSeenId: Long) {
    logger.debug("Searching refundable payments of account: ${bankAccount}," +
            " after last seen transaction id: ${lastSeenId}")
    transaction {
        TalerInvalidIncomingPaymentsTable.innerJoin(NexusBankTransactionsTable,
            { NexusBankTransactionsTable.id }, { TalerInvalidIncomingPaymentsTable.payment }).select {
            TalerInvalidIncomingPaymentsTable.refunded eq false and
                    (NexusBankTransactionsTable.bankAccount eq bankAccount.id.value) and
                    (NexusBankTransactionsTable.id greater lastSeenId)

        }.forEach {
            val paymentData = jacksonObjectMapper().readValue(
                it[NexusBankTransactionsTable.transactionJson],
                CamtBankAccountEntry::class.java
            )
            if (paymentData.batches == null) {
                logger.error("A singleton batched payment was expected to be refunded," +
                        " but none was found (in transaction (AcctSvcrRef): ${paymentData.accountServicerRef})")
                throw NexusError(HttpStatusCode.InternalServerError, "Unexpected void payment, cannot refund")
            }
            val debtorAccount = paymentData.batches[0].batchTransactions[0].details.debtorAccount
            if (debtorAccount == null || debtorAccount.iban == null) {
                logger.error("Could not find a IBAN to refund in transaction (AcctSvcrRef): ${paymentData.accountServicerRef}, aborting refund")
                throw NexusError(HttpStatusCode.InternalServerError, "IBAN to refund not found")
            }
            val debtorAgent = paymentData.batches[0].batchTransactions[0].details.debtorAgent
            if (debtorAgent?.bic == null) {
                logger.error("Could not find the BIC of refundable IBAN at transaction (AcctSvcrRef): ${paymentData.accountServicerRef}, aborting refund")
                throw NexusError(HttpStatusCode.InternalServerError, "BIC to refund not found")
            }
            val debtorPerson = paymentData.batches[0].batchTransactions[0].details.debtor
            if (debtorPerson?.name == null) {
                logger.error("Could not find the owner's name of refundable IBAN at transaction (AcctSvcrRef): ${paymentData.accountServicerRef}, aborting refund")
                throw NexusError(HttpStatusCode.InternalServerError, "Name to refund not found")
            }
            // FIXME: investigate this amount!
            val amount = paymentData.batches[0].batchTransactions[0].amount
            NexusAssert(
                it[NexusBankTransactionsTable.creditDebitIndicator] == "CRDT" &&
                        it[NexusBankTransactionsTable.bankAccount] == bankAccount.id,
                "Cannot refund a _outgoing_ payment!"
            )
            // FIXME: the amount to refund should be reduced, according to the refund fees.
            addPaymentInitiation(
                Pain001Data(
                    creditorIban = debtorAccount.iban,
                    creditorBic = debtorAgent.bic,
                    creditorName = debtorPerson.name,
                    subject = "Taler refund of: ${paymentData.batches[0].batchTransactions[0].details.unstructuredRemittanceInformation}",
                    sum = amount.value,
                    currency = amount.currency
                ),
                bankAccount // the Exchange bank account.
            )
            logger.debug("Refund of transaction (AcctSvcrRef): ${paymentData.accountServicerRef} got prepared")
            it[TalerInvalidIncomingPaymentsTable.refunded] = true
        }
    }
}

/**
 * Crawls the database to find ALL the users that have a Taler
 * facade and process their histories respecting the TWG policy.
 * The two main tasks it does are: (1) marking as invalid those
 * payments with bad subject line, and (2) see if previously requested
 * payments got booked as outgoing payments (and mark them accordingly
 * in the local table).
 */

/**
 *
 */
fun ingestTalerTransactions(bankAccountId: String) {
    fun ingest(bankAccount: NexusBankAccountEntity, facade: FacadeEntity) {
        logger.debug("Ingesting transactions for Taler facade ${facade.id.value}," +
                " and bank account: ${bankAccount.bankAccountName}")
        val facadeState = getTalerFacadeState(facade.facadeName)
        var lastId = facadeState.highestSeenMessageSerialId
        NexusBankTransactionEntity.find {
            /** Those with "our" bank account involved */
            NexusBankTransactionsTable.bankAccount eq bankAccount.id.value and
                    /** Those that are booked */
                    (NexusBankTransactionsTable.status eq EntryStatus.BOOK) and
                    /** Those that came later than the latest processed payment */
                    (NexusBankTransactionsTable.id.greater(lastId))
        }.orderBy(Pair(NexusBankTransactionsTable.id, SortOrder.ASC)).forEach {
            // Incoming payment.
            logger.debug("Taler checks payment: ${it.transactionJson}")
            val tx = jacksonObjectMapper().readValue(
                it.transactionJson, CamtBankAccountEntry::class.java
            )
            val details = tx.batches?.get(0)?.batchTransactions?.get(0)?.details
            if (details == null) {
                logger.warn("A void money movement made it through the ingestion: VERY strange")
                return@forEach
            }
            when (tx.creditDebitIndicator) {
                CreditDebitIndicator.CRDT -> {
                    ingestOneIncomingTransaction(it, txDtls = details)
                }
                else -> Unit
            }
            lastId = it.id.value
        }
        maybePrepareRefunds(bankAccount, facadeState.highestSeenMessageSerialId)
        facadeState.highestSeenMessageSerialId = lastId

    }
    // invoke ingestion for all the facades
    transaction {
        FacadeEntity.find { FacadesTable.type eq "taler-wire-gateway" }.forEach {
            val facadeBankAccount = getTalerFacadeBankAccount(it.facadeName)
            if (facadeBankAccount.bankAccountName == bankAccountId)
                ingest(facadeBankAccount, it)
        }
    }
}

/**
 * Handle a /taler/history/outgoing request.
 */
private suspend fun historyOutgoing(call: ApplicationCall) {
    val facadeId = expectNonNull(call.parameters["fcid"])
    call.request.requirePermission(PermissionQuery("facade", facadeId, "facade.talerWireGateway.history"))
    val param = call.expectUrlParameter("delta")
    val delta: Int = try {
        param.toInt()
    } catch (e: Exception) {
        throw EbicsProtocolError(HttpStatusCode.BadRequest, "'${param}' is not Int")
    }
    val start: Long = handleStartArgument(call.request.queryParameters["start"], delta)
    val startCmpOp = getComparisonOperator(delta, start, TalerRequestedPaymentsTable)
    /* retrieve database elements */
    val history = TalerOutgoingHistory()
    transaction {
        /** Retrieve all the outgoing payments from the _clean Taler outgoing table_ */
        val subscriberBankAccount = getTalerFacadeBankAccount(facadeId)
        val reqPayments = mutableListOf<TalerRequestedPaymentEntity>()
        val reqPaymentsWithUnconfirmed = TalerRequestedPaymentEntity.find {
            startCmpOp
        }.orderTaler(delta)
        reqPaymentsWithUnconfirmed.forEach {
            if (it.preparedPayment.confirmationTransaction != null) {
                reqPayments.add(it)
            }
        }
        if (reqPayments.isNotEmpty()) {
            reqPayments.subList(0, min(abs(delta), reqPayments.size)).forEach {
                history.outgoing_transactions.add(
                    TalerOutgoingBankTransaction(
                        row_id = it.id.value,
                        amount = it.amount,
                        wtid = it.wtid,
                        date = GnunetTimestamp(it.preparedPayment.preparationDate),
                        credit_account = it.creditAccount,
                        debit_account = buildIbanPaytoUri(
                            subscriberBankAccount.iban,
                            subscriberBankAccount.bankCode,
                            subscriberBankAccount.accountHolder,
                            "DBIT"
                        ),
                        exchange_base_url = "FIXME-to-request-along-subscriber-registration"
                    )
                )
            }
        }
    }
    call.respond(TextContent(customConverter(history), ContentType.Application.Json))
}

/**
 * Handle a /taler-wire-gateway/history/incoming request.
 */
private suspend fun historyIncoming(call: ApplicationCall) {
    val facadeId = expectNonNull(call.parameters["fcid"])
    call.request.requirePermission(PermissionQuery("facade", facadeId, "facade.talerWireGateway.history"))
    val param = call.expectUrlParameter("delta")
    val delta: Int = try {
        param.toInt()
    } catch (e: Exception) {
        throw EbicsProtocolError(HttpStatusCode.BadRequest, "'${param}' is not Int")
    }
    val start: Long = handleStartArgument(call.request.queryParameters["start"], delta)
    val history = TalerIncomingHistory()
    val startCmpOp = getComparisonOperator(delta, start, TalerIncomingPaymentsTable)
    transaction {
        val orderedPayments = TalerIncomingPaymentEntity.find {
            startCmpOp
        }.orderTaler(delta)
        if (orderedPayments.isNotEmpty()) {
            orderedPayments.subList(0, min(abs(delta), orderedPayments.size)).forEach {
                history.incoming_transactions.add(
                    TalerIncomingBankTransaction(
                        // Rounded timestamp
                        date = GnunetTimestamp((it.timestampMs / 1000) * 1000),
                        row_id = it.id.value,
                        amount = "${it.payment.currency}:${it.payment.amount}",
                        reserve_pub = it.reservePublicKey,
                        credit_account = buildIbanPaytoUri(
                            it.payment.bankAccount.iban,
                            it.payment.bankAccount.bankCode,
                            it.payment.bankAccount.accountHolder,
                            "CRDT"
                        ),
                        debit_account = it.debtorPaytoUri
                    )
                )
            }
        }
    }
    return call.respond(TextContent(customConverter(history), ContentType.Application.Json))
}

private fun getCurrency(facadeName: String): String {
    return transaction {
        getTalerFacadeState(facadeName).currency
    }
}

fun talerFacadeRoutes(route: Route, httpClient: HttpClient) {

    route.get("/config") {
        val facadeId = ensureNonNull(call.parameters["fcid"])
        call.request.requirePermission(PermissionQuery("facade", facadeId, "facade.talerWireGateway.config"))
        call.respond(object {
            val version = "0.0.0"
            val name = "taler-wire-gateway"
            val currency = getCurrency(facadeId)
        })
        return@get
    }
    route.post("/transfer") {
        talerTransfer(call)
        return@post
    }
    route.get("/history/outgoing") {
        historyOutgoing(call)
        return@get
    }
    route.get("/history/incoming") {
        historyIncoming(call)
        return@get
    }
    route.get("") {
        call.respondText("Hello, this is Taler Facade")
        return@get
    }
}