summaryrefslogtreecommitdiff
path: root/sandbox/src/main/kotlin/tech/libeufin
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-07-19 15:53:59 +0200
committerMS <ms@taler.net>2023-07-19 15:53:59 +0200
commitd13f040a2acb7b832a959f94a215b5e25340ed5b (patch)
tree7fb5caa126f842373027e43adbd0e77b275a9d43 /sandbox/src/main/kotlin/tech/libeufin
parentfdddd2f9f2f4d1b3daa0a74d3aeb51b51d5c8e02 (diff)
downloadlibeufin-d13f040a2acb7b832a959f94a215b5e25340ed5b.tar.gz
libeufin-d13f040a2acb7b832a959f94a215b5e25340ed5b.tar.bz2
libeufin-d13f040a2acb7b832a959f94a215b5e25340ed5b.zip
Fix /admin/add-incoming.
Avoid double-requesting in Nexus and instead create and ingest the incoming payment within the same handler.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt27
1 files changed, 23 insertions, 4 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index fab1fca6..a5c0a17f 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -1201,7 +1201,7 @@ val sandboxApp: Application.() -> Unit = {
"Invalid request"
)
}
- transaction {
+ val singletonTx = transaction {
val demobank = ensureDemobank(call)
val bankAccountCredit = getBankAccountFromLabel(username, demobank)
if (bankAccountCredit.owner != username) throw forbidden(
@@ -1209,16 +1209,35 @@ val sandboxApp: Application.() -> Unit = {
)
val bankAccountDebit = getBankAccountFromPayto(body.debit_account)
logger.debug("TWG add-incoming about to wire transfer")
- wireTransfer(
+ val ref = wireTransfer(
bankAccountDebit.label,
bankAccountCredit.label,
demobank.name,
body.reserve_pub,
body.amount
)
- logger.debug("TWG add-incoming has wire transferred")
+ /**
+ * The remaining part aims at returning an x-libeufin-bank-formatted
+ * message to Nexus, to let it ingest the (incoming side of the) payment
+ * information. The format choice makes it more practical for Nexus,
+ * because it handles this format already for the x-libeufin-bank connection
+ * type.
+ */
+ val incomingTx = BankAccountTransactionEntity.find {
+ BankAccountTransactionsTable.accountServicerReference eq ref and (
+ BankAccountTransactionsTable.direction eq "CRDT"
+ ) // closes the 'and'.
+ }.firstOrNull()
+ if (incomingTx == null)
+ throw internalServerError("Just created transaction not found in DB. AcctSvcrRef: $ref")
+ val incomingHistoryElement = getHistoryElementFromTransactionRow(incomingTx)
+ logger.debug("TWG add-incoming has wire transferred, AcctSvcrRef: $ref")
+ incomingHistoryElement
}
- call.respond(object {})
+ val resp = object {
+ val transactions = listOf(singletonTx)
+ }
+ call.respond(resp)
return@post
}
}