From 070cab1002e33479ce79b7459d6901f81cdcfdfe Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Wed, 8 Oct 2025 13:20:18 +0300 Subject: [PATCH] Merge the 2 Cadence transactions files into a single one --- services/requester/batch_tx_pool.go | 4 +- services/requester/cadence/batch_run.cdc | 35 ----------------- services/requester/cadence/run.cdc | 49 ++++++++++++++++++++---- services/requester/requester.go | 3 -- services/requester/single_tx_pool.go | 2 +- 5 files changed, 45 insertions(+), 48 deletions(-) delete mode 100644 services/requester/cadence/batch_run.cdc diff --git a/services/requester/batch_tx_pool.go b/services/requester/batch_tx_pool.go index d9810491a..daebf04cb 100644 --- a/services/requester/batch_tx_pool.go +++ b/services/requester/batch_tx_pool.go @@ -218,7 +218,7 @@ func (t *BatchTxPool) batchSubmitTransactionsForSameAddress( return err } - script := replaceAddresses(batchRunTxScript, t.config.FlowNetworkID) + script := replaceAddresses(runTxScript, t.config.FlowNetworkID) flowTx, err := t.buildTransaction( latestBlock, account, @@ -259,7 +259,7 @@ func (t *BatchTxPool) submitSingleTransaction( latestBlock, account, script, - hexEncodedTx, + cadence.NewArray([]cadence.Value{hexEncodedTx}), coinbaseAddress, ) if err != nil { diff --git a/services/requester/cadence/batch_run.cdc b/services/requester/cadence/batch_run.cdc deleted file mode 100644 index 9553b3564..000000000 --- a/services/requester/cadence/batch_run.cdc +++ /dev/null @@ -1,35 +0,0 @@ -import EVM - -transaction(hexEncodedTxs: [String], coinbase: String) { - execute { - let txs: [[UInt8]] = [] - for tx in hexEncodedTxs { - txs.append(tx.decodeHex()) - } - - let txResults = EVM.batchRun( - txs: txs, - coinbase: EVM.addressFromString(coinbase) - ) - - // If at least one of the EVM transactions in the batch is either - // failed or successful, in other words not invalid, we let the - // Cadence transaction succeed. - for txResult in txResults { - if txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful { - return - } - } - - // Otherwise, all EVM transactions are invalid txs and can't be - // executed (such as nonce too low). - // In this case, we fail the Cadence transaction with the error - // message from the first EVM transaction. - for txResult in txResults { - assert( - txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful, - message: "evm_error=\(txResult.errorMessage);evm_error_code=\(txResult.errorCode)" - ) - } - } -} diff --git a/services/requester/cadence/run.cdc b/services/requester/cadence/run.cdc index 41671c6bb..8e4911783 100644 --- a/services/requester/cadence/run.cdc +++ b/services/requester/cadence/run.cdc @@ -1,14 +1,49 @@ import EVM -transaction(hexEncodedTx: String, coinbase: String) { +transaction(hexEncodedTxs: [String], coinbase: String) { execute { - let txResult = EVM.run( - tx: hexEncodedTx.decodeHex(), + let txs: [[UInt8]] = [] + for tx in hexEncodedTxs { + txs.append(tx.decodeHex()) + } + + // If there's only one tx, use `EVM.run`. + // If there are more, then use `EVM.batchRun` + if txs.length == 1 { + let txResult = EVM.run( + tx: txs[0], + coinbase: EVM.addressFromString(coinbase) + ) + assert( + txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful, + message: "evm_error=\(txResult.errorMessage);evm_error_code=\(txResult.errorCode)" + ) + return + } + + let txResults = EVM.batchRun( + txs: txs, coinbase: EVM.addressFromString(coinbase) ) - assert( - txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful, - message: "evm_error=\(txResult.errorMessage);evm_error_code=\(txResult.errorCode)" - ) + + // If at least one of the EVM transactions in the batch is either + // failed or successful, in other words not invalid, we let the + // Cadence transaction succeed. + for txResult in txResults { + if txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful { + return + } + } + + // Otherwise, all EVM transactions are invalid txs and can't be + // executed (such as nonce too low). + // In this case, we fail the Cadence transaction with the error + // message from the first EVM transaction. + for txResult in txResults { + assert( + txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful, + message: "evm_error=\(txResult.errorMessage);evm_error_code=\(txResult.errorCode)" + ) + } } } diff --git a/services/requester/requester.go b/services/requester/requester.go index 723749912..7fe5ca5f7 100644 --- a/services/requester/requester.go +++ b/services/requester/requester.go @@ -35,9 +35,6 @@ var ( //go:embed cadence/run.cdc runTxScript []byte - //go:embed cadence/batch_run.cdc - batchRunTxScript []byte - //go:embed cadence/get_latest_evm_height.cdc getLatestEVMHeight []byte ) diff --git a/services/requester/single_tx_pool.go b/services/requester/single_tx_pool.go index d71954cd9..2deb08b38 100644 --- a/services/requester/single_tx_pool.go +++ b/services/requester/single_tx_pool.go @@ -103,7 +103,7 @@ func (t *SingleTxPool) Add( latestBlock, account, script, - hexEncodedTx, + cadence.NewArray([]cadence.Value{hexEncodedTx}), coinbaseAddress, ) if err != nil {