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

Add pending object to GraphQL queries #1419

Merged
merged 4 commits into from
May 14, 2019
Merged

Conversation

shemnon
Copy link
Contributor

@shemnon shemnon commented May 8, 2019

PR description

The initial GraphQL bounty did not include the pending object, which was not in the bounty spec. Add this for completeness.

Fixed Issue(s)

}

public Transaction getTransaction() {
return transaction;
}

public long getBlockNumber() {
public Optional<Long> getBlockNumber() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use OptionalLong here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OptionalLong is not used in this module, so using it in one place has many cascading changes. More suitable for a cleanup PR than a feature PR.

I opened PIE-1563 to clean these up in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One problem is that OptionalLong breaks some Optional.map calls. For example, this won't compile:

  public  OptionalLong getEstimateGas(final DataFetchingEnvironment environment) {
    final Optional<CallResult> result = executeCall(environment);
    return result.map(CallResult::getGasUsed);
  }

return blockHash;
}

public int getTransactionIndex() {
public Optional<Integer> getTransactionIndex() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use OptionalInt here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on OptionalLong

final Address addr = dataFetchingEnvironment.getArgument("address");
final Long bn = dataFetchingEnvironment.getArgument("blockNumber");
final long latestBn = blockchainQuery.latestBlock().get().getHeader().getNumber();
final Optional<WorldState> ows = blockchainQuery.getWorldState(latestBn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Can we use full names for the vars here? ows -> worldState; bn -> blockNumber, etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// until the miner can expose the current "proposed block" we have no
// speculative environment, so estimate against latest.
public Optional<CallResult> getCall(final DataFetchingEnvironment environment) {
return executeCall(environment);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we executing call twice? Here and in getEstimateGas? If so, anyway to dedupe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two methods specified in the EIP-1767, one that returns the entire call result and one that wants us to estimate the gas. Executing the call and getting the gasUsed is the easiest way to estimate, so they are deduped by calling executeCall (which is not exposed) and returning what we need. It could be simplified by making getCall be executeCall.

if (bn != null) {
blockNumber = bn;
final Optional<Long> txBlockNumber = transactionWithMetadata.getBlockNumber();
final Optional<Long> bn = Optional.ofNullable(environment.getArgument("block"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for the block param here to be a hash??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the spec has the block param as a Long representing the block number.

@@ -0,0 +1,22 @@
{
"request":
"{ pending { transactionCount transactions { from { address } to { address } } account(address:\"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { balance} estimateGas(data:{}) call (data : {from : \"a94f5374fce5edbc8e2a8697c15331677e6ebf0b\", to: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\", data :\"0x12a7b914\"}){data status}} }",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional) Can we format the request to be more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's json, which lacks multiline strings. And the graphql syntax for the call is not json. So no, not really.

"data": {
"pending": {
"transactionCount": 0,
"transactions": [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some more tests that return non-empty tx's here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocked in a pending transaction that will return nonce and gas.

@shemnon shemnon merged commit 1b7f056 into PegaSysEng:master May 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants