Skip to content

Commit

Permalink
Bypass for TransactionAdapter
Browse files Browse the repository at this point in the history
Signed-off-by: Wetitpig <winsto003@hotmail.com>
  • Loading branch information
Wetitpig committed Feb 29, 2024
1 parent 0fb7a23 commit d89f198
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -75,11 +78,19 @@ public Optional<UncleBlockAdapter> getOmmerAt(final DataFetchingEnvironment envi
return Optional.empty();
}

public List<TransactionAdapter> getTransactions() {
public List<TransactionAdapter> 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<TransactionWithMetadata> trans = blockWithMetaData.getTransactions();
final List<TransactionReceiptWithMetadata> transReceipts =
query.transactionReceiptsByBlockHash(hash, protocolSchedule).get();

final List<TransactionAdapter> 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;
}
Expand Down
Expand Up @@ -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<TransactionReceiptWithMetadata> getReceipt(
final DataFetchingEnvironment environment) {
if (transactionReceiptWithMetadata == null) {
Expand Down

0 comments on commit d89f198

Please sign in to comment.