executeBatch method

Future<ISendUserOperationResponse> executeBatch(
  1. List<Call> calls, [
  2. TxOptions? options
])

Executes a batch of calls in a single transaction.

calls is a list of calls to be executed. options provides additional transaction options.

Implementation

Future<ISendUserOperationResponse> executeBatch(
  List<Call> calls, [
  TxOptions? options,
]) {
  return _nonceLock.synchronized(
    () async {
      options ??= defaultTxOptions;

      if (options?.useNonceSequence ?? defaultTxOptions.useNonceSequence) {
        _nonceManager.increment();
        wallet.nonceKey = options?.customNonceKey ?? _nonceManager.retrieve();
      }

      try {
        final userOp = await wallet.executeBatch(calls);

        return await client.sendUserOperation(userOp);
      } on RPCError catch (e) {
        if ((options?.withRetry ?? defaultTxOptions.withRetry) &&
            e.message.contains(_feeTooLowError)) {
          // Use eip1559GasPrice as soon as it's available on Fuse
          final gasPrices = await legacyGasPrice(wallet.proxy.client);
          final increasedFee = _increaseFeeByPercentage(
            gasPrices['maxFeePerGas'],
            options?.feeIncrementPercentage ??
                defaultTxOptions.feeIncrementPercentage,
          );
          setWalletFees(increasedFee);

          try {
            final userOpRetry = await wallet.executeBatch(calls);

            return await client.sendUserOperation(userOpRetry);
          } catch (e) {
            rethrow;
          }
        } else {
          rethrow;
        }
      }
    },
  );
}