feature/Update Ethereum transaction request types to ETH_SEND_TRANSACTION and ETH_SEND_RAW_TRANSACTION, enhancing API endpoint definitions and internal handling

This commit is contained in:
hongwei 2025-09-24 23:11:29 +02:00
parent cc7b925203
commit dd077605e3
4 changed files with 88 additions and 12 deletions

View File

@ -122,8 +122,8 @@ trait APIMethods600 {
implementedInApiVersion,
nameOf(createTransactionRequestEthereumeSendTransaction),
"POST",
"/banks/BANK_ID/accounts/ACCOUNT_ID/owner/transaction-request-types/ETHEREUM/transaction-requests",
"Create Transaction Request (ETHEREUM)",
"/banks/BANK_ID/accounts/ACCOUNT_ID/owner/transaction-request-types/ETH_SEND_TRANSACTION/transaction-requests",
"Create Transaction Request (ETH_SEND_TRANSACTION)",
s"""
|
|Send ETH via Ethereum JSON-RPC.
@ -151,9 +151,48 @@ trait APIMethods600 {
lazy val createTransactionRequestEthereumeSendTransaction: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" ::
"ETHEREUM" :: "transaction-requests" :: Nil JsonPost json -> _ =>
"ETH_SEND_TRANSACTION" :: "transaction-requests" :: Nil JsonPost json -> _ =>
cc => implicit val ec = EndpointContext(Some(cc))
val transactionRequestType = TransactionRequestType("ETHEREUM")
val transactionRequestType = TransactionRequestType("ETH_SEND_TRANSACTION")
LocalMappedConnectorInternal.createTransactionRequest(bankId, accountId, viewId , transactionRequestType, json)
}
staticResourceDocs += ResourceDoc(
createTransactionRequestEthSendRawTransaction,
implementedInApiVersion,
nameOf(createTransactionRequestEthSendRawTransaction),
"POST",
"/banks/BANK_ID/accounts/ACCOUNT_ID/owner/transaction-request-types/ETH_SEND_RAW_TRANSACTION/transaction-requests",
"CREATE TRANSACTION REQUEST (ETH_SEND_RAW_TRANSACTION )",
s"""
|
|Send ETH via Ethereum JSON-RPC.
|AccountId should hold the 0x address for now.
|
|${transactionRequestGeneralText}
|
""".stripMargin,
transactionRequestBodyEthereumJsonV600,
transactionRequestWithChargeJSON400,
List(
$UserNotLoggedIn,
$BankNotFound,
$BankAccountNotFound,
InsufficientAuthorisationToCreateTransactionRequest,
InvalidTransactionRequestType,
InvalidJsonFormat,
NotPositiveAmount,
InvalidTransactionRequestCurrency,
TransactionDisabled,
UnknownError
),
List(apiTagTransactionRequest, apiTagPSD2PIS, apiTagPsd2)
)
lazy val createTransactionRequestEthSendRawTransaction: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" ::
"ETH_SEND_RAW_TRANSACTION" :: "transaction-requests" :: Nil JsonPost json -> _ =>
cc => implicit val ec = EndpointContext(Some(cc))
val transactionRequestType = TransactionRequestType("ETH_SEND_RAW_TRANSACTION")
LocalMappedConnectorInternal.createTransactionRequest(bankId, accountId, viewId , transactionRequestType, json)
}

View File

@ -786,7 +786,7 @@ object LocalMappedConnectorInternal extends MdcLoggable {
}
_ <- (transactionRequestTypeValue match {
case ETHEREUM => Future.successful(true) // Allow ETH (non-ISO) for Ethereum requests
case ETH_SEND_RAW_TRANSACTION | ETH_SEND_TRANSACTION => Future.successful(true) // Allow ETH (non-ISO) for Ethereum requests
case _ => Helper.booleanToFuture(s"${InvalidISOCurrencyCode} Current input is: '${transDetailsJson.value.currency}'", cc=callContext) {
APIUtil.isValidCurrencyISOCode(transDetailsJson.value.currency)
}
@ -1447,7 +1447,7 @@ object LocalMappedConnectorInternal extends MdcLoggable {
callContext)
} yield (createdTransactionRequest, callContext)
}
case ETHEREUM => {
case ETH_SEND_RAW_TRANSACTION | ETH_SEND_TRANSACTION => {
for {
transactionRequestBodyEthereum <- NewStyle.function.tryons(s"${InvalidJsonFormat} It should be $TransactionRequestBodyEthereumJsonV600 json format", 400, callContext) {
json.extract[TransactionRequestBodyEthereumJsonV600]
@ -1473,11 +1473,11 @@ object LocalMappedConnectorInternal extends MdcLoggable {
thisBankId = bankId.value,
thisAccountId = accountId.value,
thisViewId = viewId.value,
otherBankRoutingScheme = ETHEREUM.toString,
otherBankRoutingScheme = ETH_SEND_TRANSACTION.toString,
otherBankRoutingAddress = transactionRequestBodyEthereum.to,
otherBranchRoutingScheme = ETHEREUM.toString,
otherBranchRoutingScheme = ETH_SEND_TRANSACTION.toString,
otherBranchRoutingAddress = transactionRequestBodyEthereum.to,
otherAccountRoutingScheme = ETHEREUM.toString,
otherAccountRoutingScheme = ETH_SEND_TRANSACTION.toString,
otherAccountRoutingAddress = transactionRequestBodyEthereum.to,
otherAccountSecondaryRoutingScheme = "ethereum",
otherAccountSecondaryRoutingAddress = transactionRequestBodyEthereum.to,

View File

@ -59,7 +59,7 @@ class EthereumConnector_vSept2025Test extends V510ServerSetup{
// trxBody,
// amount,
// "test",
// TransactionRequestType("ETHEREUM") ,
// TransactionRequestType("ETH_SEND_TRANSACTION") ,
// "none",
// None
// )
@ -95,7 +95,43 @@ class EthereumConnector_vSept2025Test extends V510ServerSetup{
// trxBody,
// amount,
// "test",
// TransactionRequestType("ETHEREUM") ,
// TransactionRequestType("ETH_SEND_TRANSACTION") ,
// "none",
// None
// )
//
// val res = Await.result(resF, 30.seconds)
// res._1 shouldBe a [Full[_]]
// val txId = res._1.openOrThrowException(ErrorMessages.UnknownError)
// txId.value should startWith ("0x")
}
}
feature("need to start the Anvil, and set `ethereum.rpc.url=https://nkotb.openbankproject.com` in props, and prepare the from, to accounts and the rawTx") {
// setPropsValues("ethereum.rpc.url"-> "http://127.0.0.1:8545")
scenario("successful case", ConnectorTestTag) {
val from = StubBankAccount("0xf17f52151EbEF6C7334FAD080c5704D77216b732")
val to = StubBankAccount("0x627306090abaB3A6e1400e9345bC60c78a8BEf57")
val amount = BigDecimal("0.0001")
// Use a fixed rawTx variable for testing eth_sendRawTransaction path (no external params)
val rawTx = "0xf86b178203e882520894627306090abab3a6e1400e9345bc60c78a8bef57880de0b6b3a764000080820ff6a016878a008fb817df6d771749336fa0c905ec5b7fafcd043f0d9e609a2b5e41e0a0611dbe0f2ee2428360c72f4287a2996cb0d45cb8995cc23eb6ba525cb9580e02"
val trxBody = new TransactionRequestCommonBodyJSON {
override val value: AmountOfMoneyJsonV121 = AmountOfMoneyJsonV121("ETH", amount.toString)
// Put rawTx here to trigger eth_sendRawTransaction (connector uses description starting with 0x)
override val description: String = rawTx
}
// Enable integration test against private chain
// val resF = StubConnector.makePaymentv210(
// from,
// to,
// TransactionRequestId(java.util.UUID.randomUUID().toString),
// trxBody,
// amount,
// "test",
// TransactionRequestType("ETH_SEND_TRANSACTION") ,
// "none",
// None
// )

View File

@ -114,7 +114,8 @@ object TransactionRequestTypes extends OBPEnumeration[TransactionRequestTypes]{
object REFUND extends Value
object AGENT_CASH_WITHDRAWAL extends Value
object CARDANO extends Value
object ETHEREUM extends Value
object ETH_SEND_TRANSACTION extends Value
object ETH_SEND_RAW_TRANSACTION extends Value
}
sealed trait StrongCustomerAuthentication extends EnumValue