From 93c782a83016ee7de83c0c4613dbf03fde8cd9f1 Mon Sep 17 00:00:00 2001 From: Kosala Hemachandra Date: Thu, 4 Apr 2019 22:49:14 -0700 Subject: [PATCH] add multiple gas estimation --- graphql/graphql.go | 14 ++++++++++++++ graphql/schema.go | 1 + 2 files changed, 15 insertions(+) diff --git a/graphql/graphql.go b/graphql/graphql.go index b3bcbd8a43..5569a52b80 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -945,6 +945,20 @@ func (p *Pending) EstimateGas(ctx context.Context, args struct { return ethapi.DoEstimateGas(ctx, p.backend, args.Data, rpc.PendingBlockNumber) } +func (p *Pending) EstimateGases(ctx context.Context, args struct { + Data *[]ethapi.CallArgs +}) (*[]hexutil.Uint64, error) { + ret := make([]hexutil.Uint64, 0, len(*args.Data)) + for _, call := range *args.Data { + estimatedGas, err := ethapi.DoEstimateGas(ctx, p.backend, call, rpc.PendingBlockNumber) + if err != nil { + return &ret, nil + } + ret = append(ret, estimatedGas) + } + return &ret, nil +} + // Resolver is the top-level object in the GraphQL hierarchy. type Resolver struct { backend *eth.EthAPIBackend diff --git a/graphql/schema.go b/graphql/schema.go index bd913d9aa6..a7c7d791ed 100644 --- a/graphql/schema.go +++ b/graphql/schema.go @@ -289,6 +289,7 @@ const schema string = ` # EstimateGas estimates the amount of gas that will be required for # successful execution of a transaction for the pending state. estimateGas(data: CallData!): Long! + estimateGases(data: [CallData!]): [Long!] } type Query {