|
|
|
@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.graphql; |
|
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkArgument; |
|
|
|
|
|
|
|
|
|
import org.hyperledger.besu.enclave.GoQuorumEnclave; |
|
|
|
|
import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.AccountAdapter; |
|
|
|
|
import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.EmptyAccountAdapter; |
|
|
|
|
import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.LogAdapter; |
|
|
|
@ -30,6 +31,7 @@ import org.hyperledger.besu.ethereum.api.query.LogsQuery; |
|
|
|
|
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.Account; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.Address; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.GoQuorumPrivacyParameters; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.Hash; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.LogTopic; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.LogWithMetadata; |
|
|
|
@ -56,10 +58,24 @@ import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import com.google.common.base.Preconditions; |
|
|
|
|
import graphql.schema.DataFetcher; |
|
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
|
import org.apache.tuweni.bytes.Bytes; |
|
|
|
|
import org.apache.tuweni.bytes.Bytes32; |
|
|
|
|
|
|
|
|
|
public class GraphQLDataFetchers { |
|
|
|
|
|
|
|
|
|
private static final Logger LOG = LogManager.getLogger(); |
|
|
|
|
|
|
|
|
|
private Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters = Optional.empty(); |
|
|
|
|
|
|
|
|
|
public GraphQLDataFetchers( |
|
|
|
|
final Set<Capability> supportedCapabilities, |
|
|
|
|
final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters) { |
|
|
|
|
this(supportedCapabilities); |
|
|
|
|
this.goQuorumPrivacyParameters = goQuorumPrivacyParameters; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public GraphQLDataFetchers(final Set<Capability> supportedCapabilities) { |
|
|
|
|
final OptionalInt version = |
|
|
|
|
supportedCapabilities.stream() |
|
|
|
@ -259,7 +275,46 @@ public class GraphQLDataFetchers { |
|
|
|
|
((GraphQLDataFetcherContext) dataFetchingEnvironment.getContext()).getBlockchainQueries(); |
|
|
|
|
final Bytes32 hash = dataFetchingEnvironment.getArgument("hash"); |
|
|
|
|
final Optional<TransactionWithMetadata> tran = blockchain.transactionByHash(Hash.wrap(hash)); |
|
|
|
|
return tran.map(TransactionAdapter::new); |
|
|
|
|
return tran.map(this::getTransactionAdapter); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private TransactionAdapter getTransactionAdapter( |
|
|
|
|
final TransactionWithMetadata transactionWithMetadata) { |
|
|
|
|
final Transaction transaction = transactionWithMetadata.getTransaction(); |
|
|
|
|
return goQuorumPrivacyParameters.isPresent() && transaction.isGoQuorumPrivateTransaction() |
|
|
|
|
? updatePrivatePayload(transaction) |
|
|
|
|
: new TransactionAdapter(transactionWithMetadata); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private TransactionAdapter updatePrivatePayload(final Transaction transaction) { |
|
|
|
|
final GoQuorumEnclave enclave = goQuorumPrivacyParameters.get().enclave(); |
|
|
|
|
Bytes enclavePayload; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// Retrieve the payload from the enclave
|
|
|
|
|
enclavePayload = |
|
|
|
|
Bytes.wrap(enclave.receive(transaction.getPayload().toBase64String()).getPayload()); |
|
|
|
|
} catch (final Exception ex) { |
|
|
|
|
LOG.debug("An error occurred while retrieving the GoQuorum transaction payload: ", ex); |
|
|
|
|
enclavePayload = Bytes.EMPTY; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Return a new transaction containing the retrieved payload
|
|
|
|
|
return new TransactionAdapter( |
|
|
|
|
new TransactionWithMetadata( |
|
|
|
|
new Transaction( |
|
|
|
|
transaction.getNonce(), |
|
|
|
|
transaction.getGasPrice(), |
|
|
|
|
transaction.getMaxPriorityFeePerGas(), |
|
|
|
|
transaction.getMaxFeePerGas(), |
|
|
|
|
transaction.getGasLimit(), |
|
|
|
|
transaction.getTo(), |
|
|
|
|
transaction.getValue(), |
|
|
|
|
transaction.getSignature(), |
|
|
|
|
enclavePayload, |
|
|
|
|
transaction.getSender(), |
|
|
|
|
transaction.getChainId(), |
|
|
|
|
Optional.ofNullable(transaction.getV())))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|