Skip to content

Commit 070cab1

Browse files
committed
Merge the 2 Cadence transactions files into a single one
1 parent cae1289 commit 070cab1

5 files changed

Lines changed: 45 additions & 48 deletions

File tree

services/requester/batch_tx_pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (t *BatchTxPool) batchSubmitTransactionsForSameAddress(
218218
return err
219219
}
220220

221-
script := replaceAddresses(batchRunTxScript, t.config.FlowNetworkID)
221+
script := replaceAddresses(runTxScript, t.config.FlowNetworkID)
222222
flowTx, err := t.buildTransaction(
223223
latestBlock,
224224
account,
@@ -259,7 +259,7 @@ func (t *BatchTxPool) submitSingleTransaction(
259259
latestBlock,
260260
account,
261261
script,
262-
hexEncodedTx,
262+
cadence.NewArray([]cadence.Value{hexEncodedTx}),
263263
coinbaseAddress,
264264
)
265265
if err != nil {

services/requester/cadence/batch_run.cdc

Lines changed: 0 additions & 35 deletions
This file was deleted.

services/requester/cadence/run.cdc

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
11
import EVM
22

3-
transaction(hexEncodedTx: String, coinbase: String) {
3+
transaction(hexEncodedTxs: [String], coinbase: String) {
44
execute {
5-
let txResult = EVM.run(
6-
tx: hexEncodedTx.decodeHex(),
5+
let txs: [[UInt8]] = []
6+
for tx in hexEncodedTxs {
7+
txs.append(tx.decodeHex())
8+
}
9+
10+
// If there's only one tx, use `EVM.run`.
11+
// If there are more, then use `EVM.batchRun`
12+
if txs.length == 1 {
13+
let txResult = EVM.run(
14+
tx: txs[0],
15+
coinbase: EVM.addressFromString(coinbase)
16+
)
17+
assert(
18+
txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful,
19+
message: "evm_error=\(txResult.errorMessage);evm_error_code=\(txResult.errorCode)"
20+
)
21+
return
22+
}
23+
24+
let txResults = EVM.batchRun(
25+
txs: txs,
726
coinbase: EVM.addressFromString(coinbase)
827
)
9-
assert(
10-
txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful,
11-
message: "evm_error=\(txResult.errorMessage);evm_error_code=\(txResult.errorCode)"
12-
)
28+
29+
// If at least one of the EVM transactions in the batch is either
30+
// failed or successful, in other words not invalid, we let the
31+
// Cadence transaction succeed.
32+
for txResult in txResults {
33+
if txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful {
34+
return
35+
}
36+
}
37+
38+
// Otherwise, all EVM transactions are invalid txs and can't be
39+
// executed (such as nonce too low).
40+
// In this case, we fail the Cadence transaction with the error
41+
// message from the first EVM transaction.
42+
for txResult in txResults {
43+
assert(
44+
txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful,
45+
message: "evm_error=\(txResult.errorMessage);evm_error_code=\(txResult.errorCode)"
46+
)
47+
}
1348
}
1449
}

services/requester/requester.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ var (
3535
//go:embed cadence/run.cdc
3636
runTxScript []byte
3737

38-
//go:embed cadence/batch_run.cdc
39-
batchRunTxScript []byte
40-
4138
//go:embed cadence/get_latest_evm_height.cdc
4239
getLatestEVMHeight []byte
4340
)

services/requester/single_tx_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (t *SingleTxPool) Add(
103103
latestBlock,
104104
account,
105105
script,
106-
hexEncodedTx,
106+
cadence.NewArray([]cadence.Value{hexEncodedTx}),
107107
coinbaseAddress,
108108
)
109109
if err != nil {

0 commit comments

Comments
 (0)