f91312dbdb
* Initial work on a graphql API * Added receipts, and more transaction fields. * Finish receipts, add logs * Add transactionCount to block * Add types and . * Update Block type to be compatible with ethql * Rename nonce to transactionCount in Account, to be compatible with ethql * Update transaction, receipt and log to match ethql * Add query operator, for a range of blocks * Added ommerCount to Block * Add transactionAt and ommerAt to Block * Added sendRawTransaction mutation * Add Call and EstimateGas to graphQL API * Refactored to use hexutil.Bytes instead of HexBytes * Replace BigNum with hexutil.Big * Refactor call and estimateGas to use ethapi struct type * Replace ethgraphql.Address with common.Address * Replace ethgraphql.Hash with common.Hash * Converted most quantities to Long instead of Int * Add support for logs * Fix bug in runFilter * Restructured Transaction to work primarily with headers, so uncle data is reported properly * Add gasPrice API * Add protocolVersion API * Add syncing API * Moved schema into its own source file * Move some single use args types into anonymous structs * Add doc-comments * Fixed backend fetching to use context * Added (very) basic tests * Add documentation to the graphql schema * Fix reversion for formatting of big numbers * Correct spelling error * s/BigInt/Long/ * Update common/types.go * Fixes in response to review * Fix lint error * Updated calls on private functions * Fix typo in graphql.go * Rollback ethapi breaking changes for graphql support Co-Authored-By: Arachnid <arachnid@notdot.net>
79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package common
|
|
|
|
import (
|
|
"github.com/graph-gophers/graphql-go/errors"
|
|
)
|
|
|
|
// http://facebook.github.io/graphql/draft/#InputValueDefinition
|
|
type InputValue struct {
|
|
Name Ident
|
|
Type Type
|
|
Default Literal
|
|
Desc string
|
|
Loc errors.Location
|
|
TypeLoc errors.Location
|
|
}
|
|
|
|
type InputValueList []*InputValue
|
|
|
|
func (l InputValueList) Get(name string) *InputValue {
|
|
for _, v := range l {
|
|
if v.Name.Name == name {
|
|
return v
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ParseInputValue(l *Lexer) *InputValue {
|
|
p := &InputValue{}
|
|
p.Loc = l.Location()
|
|
p.Desc = l.DescComment()
|
|
p.Name = l.ConsumeIdentWithLoc()
|
|
l.ConsumeToken(':')
|
|
p.TypeLoc = l.Location()
|
|
p.Type = ParseType(l)
|
|
if l.Peek() == '=' {
|
|
l.ConsumeToken('=')
|
|
p.Default = ParseLiteral(l, true)
|
|
}
|
|
return p
|
|
}
|
|
|
|
type Argument struct {
|
|
Name Ident
|
|
Value Literal
|
|
}
|
|
|
|
type ArgumentList []Argument
|
|
|
|
func (l ArgumentList) Get(name string) (Literal, bool) {
|
|
for _, arg := range l {
|
|
if arg.Name.Name == name {
|
|
return arg.Value, true
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func (l ArgumentList) MustGet(name string) Literal {
|
|
value, ok := l.Get(name)
|
|
if !ok {
|
|
panic("argument not found")
|
|
}
|
|
return value
|
|
}
|
|
|
|
func ParseArguments(l *Lexer) ArgumentList {
|
|
var args ArgumentList
|
|
l.ConsumeToken('(')
|
|
for l.Peek() != ')' {
|
|
name := l.ConsumeIdentWithLoc()
|
|
l.ConsumeToken(':')
|
|
value := ParseLiteral(l, false)
|
|
args = append(args, Argument{Name: name, Value: value})
|
|
}
|
|
l.ConsumeToken(')')
|
|
return args
|
|
}
|