protected static List<Transaction> extractTransactions(
      final PrintWriter out,
      final Iterator<JsonNode> it,
      final List<Transaction> transactions,
      final List<RejectedTransaction> rejections) {
    int i = 0;
    while (it.hasNext()) {
      try {
        JsonNode txNode = it.next();
        if (txNode.isTextual()) {
          BytesValueRLPInput rlpInput =
              new BytesValueRLPInput(Bytes.fromHexString(txNode.asText()), false);
          rlpInput.enterList();
          while (!rlpInput.isEndOfCurrentList()) {
            Transaction tx = Transaction.readFrom(rlpInput);
            transactions.add(tx);
          }
        } else if (txNode.isObject()) {
          if (txNode.has("txBytes")) {
            Transaction tx =
                Transaction.readFrom(Bytes.fromHexString(txNode.get("txbytes").asText()));
            transactions.add(tx);
          } else {
            Transaction.Builder builder = Transaction.builder();
            int type = Bytes.fromHexStringLenient(txNode.get("type").textValue()).toInt();
            BigInteger chainId =
                Bytes.fromHexStringLenient(txNode.get("chainId").textValue())
                    .toUnsignedBigInteger();
            TransactionType transactionType = TransactionType.of(type == 0 ? 0xf8 : type);
            builder.type(transactionType);
            builder.nonce(Bytes.fromHexStringLenient(txNode.get("nonce").textValue()).toLong());
            builder.gasLimit(Bytes.fromHexStringLenient(txNode.get("gas").textValue()).toLong());
            builder.value(Wei.fromHexString(txNode.get("value").textValue()));
            builder.payload(Bytes.fromHexString(txNode.get("input").textValue()));

            if (txNode.has("gasPrice")) {
              builder.gasPrice(Wei.fromHexString(txNode.get("gasPrice").textValue()));
            }
            if (txNode.has("maxPriorityFeePerGas")) {
              builder.maxPriorityFeePerGas(
                  Wei.fromHexString(txNode.get("maxPriorityFeePerGas").textValue()));
            }
            if (txNode.has("maxFeePerGas")) {
              builder.maxFeePerGas(Wei.fromHexString(txNode.get("maxFeePerGas").textValue()));
            }
            if (txNode.has("maxFeePerBlobGas")) {
              builder.maxFeePerBlobGas(
                  Wei.fromHexString(txNode.get("maxFeePerBlobGas").textValue()));
            }

            if (txNode.has("to")) {
              builder.to(Address.fromHexString(txNode.get("to").textValue()));
            }
            BigInteger v =
                Bytes.fromHexStringLenient(txNode.get("v").textValue()).toUnsignedBigInteger();
            if (transactionType.requiresChainId() || (v.compareTo(REPLAY_PROTECTED_V_MIN) > 0)) {
              // chainid if protected
              builder.chainId(chainId);
            }

            if (txNode.has("accessList")) {
              JsonNode accessList = txNode.get("accessList");
              if (!accessList.isArray()) {
                out.printf(
                    "TX json node unparseable: expected accessList to be an array - %s%n", txNode);
                continue;
              }
              List<AccessListEntry> entries = new ArrayList<>(accessList.size());
              for (JsonNode entryAsJson : accessList) {
                Address address = Address.fromHexString(entryAsJson.get("address").textValue());
                List<String> storageKeys =
                    StreamSupport.stream(
                            Spliterators.spliteratorUnknownSize(
                                entryAsJson.get("storageKeys").elements(), Spliterator.ORDERED),
                            false)
                        .map(JsonNode::textValue)
                        .toList();
                AccessListEntry accessListEntry =
                    AccessListEntry.createAccessListEntry(address, storageKeys);
                entries.add(accessListEntry);
              }
              builder.accessList(entries);
            }

            if (txNode.has("authorizationList")) {
              JsonNode authorizationList = txNode.get("authorizationList");

              if (!authorizationList.isArray()) {
                out.printf(
                    "TX json node unparseable: expected authorizationList to be an array - %s%n",
                    txNode);
                continue;
              }

              List<CodeDelegation> codeDelegations = new ArrayList<>(authorizationList.size());
              for (JsonNode entryAsJson : authorizationList) {
                final BigInteger codeDelegationChainId =
                    Bytes.fromHexStringLenient(entryAsJson.get("chainId").textValue())
                        .toUnsignedBigInteger();
                final Address codeDelegationAddress =
                    Address.fromHexString(entryAsJson.get("address").textValue());

                final long codeDelegationNonce =
                    Bytes.fromHexStringLenient(entryAsJson.get("nonce").textValue()).toLong();

                final BigInteger codeDelegationV =
                    Bytes.fromHexStringLenient(entryAsJson.get("v").textValue())
                        .toUnsignedBigInteger();
                if (codeDelegationV.compareTo(BigInteger.valueOf(256)) >= 0) {
                  throw new IllegalArgumentException(
                      "Invalid codeDelegationV value. Must be less than 256");
                }

                final BigInteger codeDelegationR =
                    Bytes.fromHexStringLenient(entryAsJson.get("r").textValue())
                        .toUnsignedBigInteger();
                final BigInteger codeDelegationS =
                    Bytes.fromHexStringLenient(entryAsJson.get("s").textValue())
                        .toUnsignedBigInteger();

                final SECPSignature codeDelegationSignature =
                    new SECPSignature(
                        codeDelegationR, codeDelegationS, codeDelegationV.byteValue());

                codeDelegations.add(
                    new org.hyperledger.besu.ethereum.core.CodeDelegation(
                        codeDelegationChainId,
                        codeDelegationAddress,
                        codeDelegationNonce,
                        codeDelegationSignature));
              }
              builder.codeDelegations(codeDelegations);
            }

            if (txNode.has("blobVersionedHashes")) {
              JsonNode blobVersionedHashes = txNode.get("blobVersionedHashes");
              if (!blobVersionedHashes.isArray()) {
                out.printf(
                    "TX json node unparseable: expected blobVersionedHashes to be an array - %s%n",
                    txNode);
                continue;
              }

              List<VersionedHash> entries = new ArrayList<>(blobVersionedHashes.size());
              for (JsonNode versionedHashNode : blobVersionedHashes) {
                entries.add(
                    new VersionedHash(Bytes32.fromHexString(versionedHashNode.textValue())));
              }
              builder.versionedHashes(entries);
            }

            if (txNode.has("secretKey")) {
              SignatureAlgorithm signatureAlgorithm = SignatureAlgorithmFactory.getInstance();
              KeyPair keys =
                  signatureAlgorithm.createKeyPair(
                      signatureAlgorithm.createPrivateKey(
                          Bytes32.fromHexString(txNode.get("secretKey").textValue())));

              transactions.add(builder.signAndBuild(keys));
            } else {
              if (transactionType == TransactionType.FRONTIER) {
                if (v.compareTo(REPLAY_PROTECTED_V_MIN) > 0) {
                  v =
                      v.subtract(REPLAY_PROTECTED_V_BASE)
                          .subtract(chainId.multiply(BigInteger.TWO));
                } else {
                  v = v.subtract(REPLAY_UNPROTECTED_V_BASE);
                }
              }
              builder.signature(
                  SignatureAlgorithmFactory.getInstance()
                      .createSignature(
                          Bytes.fromHexStringLenient(txNode.get("r").textValue())
                              .toUnsignedBigInteger(),
                          Bytes.fromHexStringLenient(txNode.get("s").textValue())
                              .toUnsignedBigInteger(),
                          v.byteValueExact()));

              final Transaction tx = builder.build();

              transactions.add(tx);
            }
          }
        } else {
          out.printf("TX json node unparseable: %s%n", txNode);
        }
      } catch (IllegalArgumentException | ArithmeticException e) {
        rejections.add(new RejectedTransaction(i, e.getMessage()));
      }
      i++;
    }
    return transactions;
  }
Extracts transactions from a given JSON iterator and adds them to the provided transactions
list. If a transaction cannot be parsed or is invalid, it is added to the rejections list with
its index and error message.

@param out PrintWriter used for outputting information or errors.
@param it Iterator over JSON nodes, each representing a transaction.
@param transactions List of transactions to which parsed transactions are added.
@param rejections List of RejectedTransaction records to which rejected transactions are added.
@return The updated list of transactions after parsing and validation.
ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java