From ae09fcb5e41700d75d621b90fd3567467c039776 Mon Sep 17 00:00:00 2001 From: Wetitpig Date: Thu, 29 Feb 2024 18:50:00 +0800 Subject: [PATCH] Bypass for `TransactionAdapter` Signed-off-by: Wetitpig --- .../pojoadapter/NormalBlockAdapter.java | 17 ++++++++++++++--- .../pojoadapter/TransactionAdapter.java | 7 +++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java index f54b3f0da04..6e23f116c4b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java @@ -15,11 +15,14 @@ package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter; import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.ethereum.api.graphql.GraphQLContextType; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.api.query.TransactionReceiptWithMetadata; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.util.ArrayList; import java.util.List; @@ -75,11 +78,19 @@ public Optional getOmmerAt(final DataFetchingEnvironment envi return Optional.empty(); } - public List getTransactions() { + public List getTransactions(final DataFetchingEnvironment environment) { + final BlockchainQueries query = getBlockchainQueries(environment); + final Hash hash = blockWithMetaData.getHeader().getHash(); + final ProtocolSchedule protocolSchedule = + environment.getGraphQlContext().get(GraphQLContextType.PROTOCOL_SCHEDULE); + final List trans = blockWithMetaData.getTransactions(); + final List transReceipts = + query.transactionReceiptsByBlockHash(hash, protocolSchedule).get(); + final List results = new ArrayList<>(); - for (final TransactionWithMetadata tran : trans) { - results.add(new TransactionAdapter(tran)); + for (int i = 0; i < trans.size(); i++) { + results.add(new TransactionAdapter(trans.get(i), transReceipts.get(i))); } return results; } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java index f3ead13dadb..ced0d24882b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java @@ -46,6 +46,13 @@ public TransactionAdapter(final @Nonnull TransactionWithMetadata transactionWith this.transactionWithMetadata = transactionWithMetadata; } + public TransactionAdapter( + final @Nonnull TransactionWithMetadata transactionWithMetadata, + final @Nonnull TransactionReceiptWithMetadata transactionReceiptWithMetadata) { + this.transactionWithMetadata = transactionWithMetadata; + this.transactionReceiptWithMetadata = Optional.of(transactionReceiptWithMetadata); + } + private Optional getReceipt( final DataFetchingEnvironment environment) { if (transactionReceiptWithMetadata == null) {