Return `address` from the `from` and `to` fields in a GraphQL (#6198)

When the world state is not retrievable, instead of returning java.lang.reflect.InvocationTargetException in the from field and null in the to field in GraphQL, return an empty account with the address only.

Signed-off-by: Wetitpig <winsto003@hotmail.com>
Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
pull/6215/head
Wetitpig 1 year ago committed by GitHub
parent bae1939c63
commit 1f72632e19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/LogAdapter.java
  3. 49
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java

@ -13,6 +13,7 @@
- Update OpenJDK latest Docker image to use Java 21 [#6189](https://github.com/hyperledger/besu/pull/6189) - Update OpenJDK latest Docker image to use Java 21 [#6189](https://github.com/hyperledger/besu/pull/6189)
- Allow a transaction selection plugin to specify custom selection results [#6190](https://github.com/hyperledger/besu/pull/6190) - Allow a transaction selection plugin to specify custom selection results [#6190](https://github.com/hyperledger/besu/pull/6190)
- Add `rpc-gas-cap` to allow users to set gas limit to the RPC methods used to simulate transactions[#6156](https://github.com/hyperledger/besu/pull/6156) - Add `rpc-gas-cap` to allow users to set gas limit to the RPC methods used to simulate transactions[#6156](https://github.com/hyperledger/besu/pull/6156)
- Fix the unavailability of `address` field when returning an `Account` entity on GraphQL in case of unreachable world state [#6198](https://github.com/hyperledger/besu/pull/6198)
### Bug fixes ### Bug fixes
- Fix Docker image name clash between Besu and evmtool [#6194](https://github.com/hyperledger/besu/pull/6194) - Fix Docker image name clash between Besu and evmtool [#6194](https://github.com/hyperledger/besu/pull/6194)

@ -14,6 +14,7 @@
*/ */
package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter; package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;
@ -63,9 +64,9 @@ public class LogAdapter extends AdapterBase {
blockNumber = bn; blockNumber = bn;
} }
final Address logger = logWithMetadata.getLogger();
return query return query
.getAndMapWorldState( .getAndMapWorldState(blockNumber, ws -> Optional.of(new AccountAdapter(ws.get(logger))))
blockNumber, ws -> Optional.of(new AccountAdapter(ws.get(logWithMetadata.getLogger())))) .orElse(new EmptyAccountAdapter(logger));
.get();
} }
} }

@ -82,35 +82,36 @@ public class TransactionAdapter extends AdapterBase {
public AccountAdapter getFrom(final DataFetchingEnvironment environment) { public AccountAdapter getFrom(final DataFetchingEnvironment environment) {
final BlockchainQueries query = getBlockchainQueries(environment); final BlockchainQueries query = getBlockchainQueries(environment);
Long blockNumber = environment.getArgument("block"); final Long blockNumber =
if (blockNumber == null) { Optional.<Long>ofNullable(environment.getArgument("block"))
blockNumber = transactionWithMetadata.getBlockNumber().orElseGet(query::headBlockNumber); .or(transactionWithMetadata::getBlockNumber)
} .orElseGet(query::headBlockNumber);
final Address addr = transactionWithMetadata.getTransaction().getSender();
return query return query
.getAndMapWorldState( .getAndMapWorldState(
blockNumber, blockNumber,
mutableWorldState -> mutableWorldState -> Optional.of(new AccountAdapter(mutableWorldState.get(addr))))
Optional.of( .orElse(new EmptyAccountAdapter(addr));
new AccountAdapter(
mutableWorldState.get(
transactionWithMetadata.getTransaction().getSender()))))
.get();
} }
public Optional<AccountAdapter> getTo(final DataFetchingEnvironment environment) { public Optional<AccountAdapter> getTo(final DataFetchingEnvironment environment) {
final BlockchainQueries query = getBlockchainQueries(environment); final BlockchainQueries query = getBlockchainQueries(environment);
Long blockNumber = environment.getArgument("block"); final Long blockNumber =
if (blockNumber == null) { Optional.<Long>ofNullable(environment.getArgument("block"))
blockNumber = transactionWithMetadata.getBlockNumber().orElseGet(query::headBlockNumber); .or(transactionWithMetadata::getBlockNumber)
} .orElseGet(query::headBlockNumber);
return query.getAndMapWorldState( return transactionWithMetadata
blockNumber, .getTransaction()
ws -> .getTo()
transactionWithMetadata .flatMap(
.getTransaction() address ->
.getTo() query
.map(address -> new AccountAdapter(address, ws.get(address)))); .getAndMapWorldState(
blockNumber,
ws -> Optional.of(new AccountAdapter(address, ws.get(address))))
.or(() -> Optional.of(new EmptyAccountAdapter(address))));
} }
public Wei getValue() { public Wei getValue() {
@ -197,8 +198,10 @@ public class TransactionAdapter extends AdapterBase {
return Optional.empty(); return Optional.empty();
} }
final long blockNumber = bn.orElseGet(txBlockNumber::get); final long blockNumber = bn.orElseGet(txBlockNumber::get);
return query.getAndMapWorldState( return query
blockNumber, ws -> Optional.of(new AccountAdapter(ws.get(addr.get())))); .getAndMapWorldState(
blockNumber, ws -> Optional.of(new AccountAdapter(ws.get(addr.get()))))
.or(() -> Optional.of(new EmptyAccountAdapter(addr.get())));
} }
} }
return Optional.empty(); return Optional.empty();

Loading…
Cancel
Save