refactor/Update Ethereum transaction request structure to simplify JSON model and improve code readability

This commit is contained in:
hongwei 2025-09-24 08:54:09 +02:00
parent 5db5db2886
commit 7ff31a1f55
4 changed files with 12 additions and 18 deletions

View File

@ -5742,9 +5742,7 @@ object SwaggerDefinitionsJSON {
)
lazy val transactionRequestBodyEthereumJsonV600 = TransactionRequestBodyEthereumJsonV600(
payment = EthereumPaymentJsonV600(
to = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
),
to = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
value = AmountOfMoneyJsonV121("ETH", "0.01"),
description = descriptionExample.value
)

View File

@ -118,9 +118,9 @@ trait APIMethods600 {
}
staticResourceDocs += ResourceDoc(
createTransactionRequestEthereum,
createTransactionRequestEthereumeSendTransaction,
implementedInApiVersion,
nameOf(createTransactionRequestEthereum),
nameOf(createTransactionRequestEthereumeSendTransaction),
"POST",
"/banks/BANK_ID/accounts/ACCOUNT_ID/owner/transaction-request-types/ETHEREUM/transaction-requests",
"Create Transaction Request (ETHEREUM)",
@ -149,7 +149,7 @@ trait APIMethods600 {
List(apiTagTransactionRequest, apiTagPSD2PIS, apiTagPsd2)
)
lazy val createTransactionRequestEthereum: OBPEndpoint = {
lazy val createTransactionRequestEthereumeSendTransaction: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" ::
"ETHEREUM" :: "transaction-requests" :: Nil JsonPost json -> _ =>
cc => implicit val ec = EndpointContext(Some(cc))

View File

@ -64,12 +64,8 @@ case class TransactionRequestBodyCardanoJsonV600(
) extends TransactionRequestCommonBodyJSON
// ---------------- Ethereum models (V600) ----------------
case class EthereumPaymentJsonV600(
to: String // 0x address
)
case class TransactionRequestBodyEthereumJsonV600(
payment: EthereumPaymentJsonV600,
to: String, // 0x address
value: AmountOfMoneyJsonV121, // currency should be "ETH"; amount string (decimal)
description: String
) extends TransactionRequestCommonBodyJSON

View File

@ -1454,10 +1454,10 @@ object LocalMappedConnectorInternal extends MdcLoggable {
}
// Basic validations
_ <- Helper.booleanToFuture(s"$InvalidJsonValue Ethereum 'to' address is required", cc=callContext) {
Option(transactionRequestBodyEthereum.payment.to).exists(_.nonEmpty)
Option(transactionRequestBodyEthereum.to).exists(_.nonEmpty)
}
_ <- Helper.booleanToFuture(s"$InvalidJsonValue Ethereum 'to' address must start with 0x and be 42 chars", cc=callContext) {
val toBody = transactionRequestBodyEthereum.payment.to
val toBody = transactionRequestBodyEthereum.to
toBody.startsWith("0x") && toBody.length == 42
}
_ <- Helper.booleanToFuture(s"$InvalidTransactionRequestCurrency Currency must be 'ETH'", cc=callContext) {
@ -1466,7 +1466,7 @@ object LocalMappedConnectorInternal extends MdcLoggable {
// Create or get counterparty using the Ethereum address as secondary routing
(toCounterparty, callContext) <- NewStyle.function.getOrCreateCounterparty(
name = "ethereum-" + transactionRequestBodyEthereum.payment.to.take(27),
name = "ethereum-" + transactionRequestBodyEthereum.to.take(27),
description = transactionRequestBodyEthereum.description,
currency = transactionRequestBodyEthereum.value.currency,
createdByUserId = u.userId,
@ -1474,13 +1474,13 @@ object LocalMappedConnectorInternal extends MdcLoggable {
thisAccountId = accountId.value,
thisViewId = viewId.value,
otherBankRoutingScheme = ETHEREUM.toString,
otherBankRoutingAddress = transactionRequestBodyEthereum.payment.to,
otherBankRoutingAddress = transactionRequestBodyEthereum.to,
otherBranchRoutingScheme = ETHEREUM.toString,
otherBranchRoutingAddress = transactionRequestBodyEthereum.payment.to,
otherBranchRoutingAddress = transactionRequestBodyEthereum.to,
otherAccountRoutingScheme = ETHEREUM.toString,
otherAccountRoutingAddress = transactionRequestBodyEthereum.payment.to,
otherAccountRoutingAddress = transactionRequestBodyEthereum.to,
otherAccountSecondaryRoutingScheme = "ethereum",
otherAccountSecondaryRoutingAddress = transactionRequestBodyEthereum.payment.to,
otherAccountSecondaryRoutingAddress = transactionRequestBodyEthereum.to,
callContext = callContext
)