Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2705] helpful graphql error when an account doesn't exist #1460

Merged
merged 2 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
*/
package tech.pegasys.pantheon.ethereum.graphqlrpc;

import static com.google.common.base.Preconditions.checkArgument;

import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.core.Account;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.SyncStatus;
Expand Down Expand Up @@ -163,19 +166,28 @@ DataFetcher<Optional<AccountAdapter>> getAccountDataFetcher() {
if (bn != null) {
final Optional<WorldState> ws = blockchainQuery.getWorldState(bn);
if (ws.isPresent()) {
return Optional.of(new AccountAdapter(ws.get().get(addr)));
final Account account = ws.get().get(addr);
checkArgument(account != null, "Account with address %s does not exist", addr);
return Optional.of(new AccountAdapter(account));
} else if (bn > blockchainQuery.getBlockchain().getChainHeadBlockNumber()) {
// block is past chainhead
throw new GraphQLRpcException(GraphQLRpcError.INVALID_PARAMS);
} else {
// we don't have that block
throw new GraphQLRpcException(GraphQLRpcError.CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE);
}
} else {
// return account on latest block
final long latestBn = blockchainQuery.latestBlock().get().getHeader().getNumber();
final Optional<WorldState> ows = blockchainQuery.getWorldState(latestBn);
return ows.flatMap(
ws -> {
Account account = ws.get(addr);
checkArgument(account != null, "Account with address %s does not exist", addr);
return Optional.ofNullable(account);
})
.map(AccountAdapter::new);
}
// return account on latest block
final long latestBn = blockchainQuery.latestBlock().get().getHeader().getNumber();
final Optional<WorldState> ows = blockchainQuery.getWorldState(latestBn);
return ows.flatMap(ws -> Optional.ofNullable(ws.get(addr))).map(AccountAdapter::new);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public static Collection<String> specs() {
specs.add("eth_call_BlockLatest");
specs.add("eth_getBalance_latest");
specs.add("eth_getBalance_0x19");
specs.add("eth_getBalance_invalidAccountBlockNumber");
specs.add("eth_getBalance_invalidAccountLatest");
specs.add("eth_gasPrice");

specs.add("eth_getTransactionReceipt");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"request": "{account(blockNumber:\"0x19\", address: \"0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef\") { balance } }",
"response": {
"data": null,
"errors": [
{
"message": "Exception while fetching data (/account) : Account with address 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef does not exist",
"locations": [
{
"line": 1,
"column": 2
}
],
"path": [
"account"
]
}
]
},
"statusCode": 400
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"request": "{account(address: \"0xdeaff00ddeaff00ddeaff00ddeaff00ddeaff00d\") { balance } }",
"response": {
"data": null,
"errors": [
{
"message": "Exception while fetching data (/account) : Account with address 0xdeaff00ddeaff00ddeaff00ddeaff00ddeaff00d does not exist",
"locations": [
{
"line": 1,
"column": 2
}
],
"path": [
"account"
]
}
]
},
"statusCode": 400
}