graphql

package
v4.2.8-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2023 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package graphql provides a GraphQL interface to Ethereum node data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(backend *eth.Backend) (http.Handler, error)

newHandler returns a new `http.Handler` that will answer GraphQL queries. It additionally exports an interactive query browser on the / endpoint.

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

Account represents an Ethereum account at a particular block.

func (*Account) Address

func (a *Account) Address(ctx context.Context) (common.Address, error)

func (*Account) Balance

func (a *Account) Balance(ctx context.Context) (hexutil.Big, error)

func (*Account) Code

func (a *Account) Code(ctx context.Context) (hexutil.Bytes, error)

func (*Account) Storage

func (a *Account) Storage(ctx context.Context, args struct{ Slot common.Hash }) (common.Hash, error)

func (*Account) TransactionCount

func (a *Account) TransactionCount(ctx context.Context) (hexutil.Uint64, error)

type AllEthHeaderCIDs

type AllEthHeaderCIDs struct {
	Response AllEthHeaderCIDsResponse `json:"allEthHeaderCids"`
}

type AllEthHeaderCIDsResponse

type AllEthHeaderCIDsResponse struct {
	Nodes []EthHeaderCIDResponse `json:"nodes"`
}

type BigInt

type BigInt big.Int

func (BigInt) ImplementsGraphQLType

func (b BigInt) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if BigInt implements the provided GraphQL type.

func (BigInt) MarshalText

func (b BigInt) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*BigInt) SetUint64

func (b *BigInt) SetUint64(x uint64) *BigInt

SetUint64 sets b to x and returns x.

func (*BigInt) String

func (b *BigInt) String() string

String returns value of b as a decimal string.

func (*BigInt) ToInt

func (b *BigInt) ToInt() *big.Int

ToInt converts b to a big.Int.

func (*BigInt) UnmarshalGraphQL

func (b *BigInt) UnmarshalGraphQL(input interface{}) error

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*BigInt) UnmarshalText

func (b *BigInt) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Block

type Block struct {
	// contains filtered or unexported fields
}

Block represents an Ethereum block. backend, and numberOrHash are mandatory. All other fields are lazily fetched when required.

func (*Block) Account

func (b *Block) Account(ctx context.Context, args struct {
	Address common.Address
}) (*Account, error)

func (*Block) Call

func (b *Block) Call(ctx context.Context, args struct {
	Data eth.CallArgs
}) (*CallResult, error)

func (*Block) Difficulty

func (b *Block) Difficulty(ctx context.Context) (hexutil.Big, error)

func (*Block) ExtraData

func (b *Block) ExtraData(ctx context.Context) (hexutil.Bytes, error)

func (*Block) GasLimit

func (b *Block) GasLimit(ctx context.Context) (hexutil.Uint64, error)

func (*Block) GasUsed

func (b *Block) GasUsed(ctx context.Context) (hexutil.Uint64, error)

func (*Block) Hash

func (b *Block) Hash(ctx context.Context) (common.Hash, error)

func (*Block) Logs

func (b *Block) Logs(ctx context.Context, args struct{ Filter BlockFilterCriteria }) ([]*Log, error)

func (*Block) LogsBloom

func (b *Block) LogsBloom(ctx context.Context) (hexutil.Bytes, error)

func (*Block) Miner

func (b *Block) Miner(ctx context.Context, args BlockNumberArgs) (*Account, error)

func (*Block) MixHash

func (b *Block) MixHash(ctx context.Context) (common.Hash, error)

func (*Block) Nonce

func (b *Block) Nonce(ctx context.Context) (hexutil.Bytes, error)

func (*Block) Number

func (b *Block) Number(ctx context.Context) (hexutil.Uint64, error)

func (*Block) OmmerAt

func (b *Block) OmmerAt(ctx context.Context, args struct{ Index int32 }) (*Block, error)

func (*Block) OmmerCount

func (b *Block) OmmerCount(ctx context.Context) (*int32, error)

func (*Block) OmmerHash

func (b *Block) OmmerHash(ctx context.Context) (common.Hash, error)

func (*Block) Ommers

func (b *Block) Ommers(ctx context.Context) (*[]*Block, error)

func (*Block) Parent

func (b *Block) Parent(ctx context.Context) (*Block, error)

func (*Block) ReceiptsRoot

func (b *Block) ReceiptsRoot(ctx context.Context) (common.Hash, error)

func (*Block) StateRoot

func (b *Block) StateRoot(ctx context.Context) (common.Hash, error)

func (*Block) Timestamp

func (b *Block) Timestamp(ctx context.Context) (hexutil.Uint64, error)

func (*Block) TotalDifficulty

func (b *Block) TotalDifficulty(ctx context.Context) (hexutil.Big, error)

func (*Block) TransactionAt

func (b *Block) TransactionAt(ctx context.Context, args struct{ Index int32 }) (*Transaction, error)

func (*Block) TransactionCount

func (b *Block) TransactionCount(ctx context.Context) (*int32, error)

func (*Block) Transactions

func (b *Block) Transactions(ctx context.Context) (*[]*Transaction, error)

func (*Block) TransactionsRoot

func (b *Block) TransactionsRoot(ctx context.Context) (common.Hash, error)

type BlockFilterCriteria

type BlockFilterCriteria struct {
	Addresses *[]common.Address // restricts matches to events created by specific contracts

	// The Topic list restricts matches to particular event topics. Each event has a list
	// of topics. Topics matches a prefix of that list. An empty element slice matches any
	// topic. Non-empty elements represent an alternative that matches any of the
	// contained topics.
	//
	// Examples:
	// {} or nil          matches any topic list
	// {{A}}              matches topic A in first position
	// {{}, {B}}          matches any topic in first position, B in second position
	// {{A}, {B}}         matches topic A in first position, B in second position
	// {{A, B}}, {C, D}}  matches topic (A OR B) in first position, (C OR D) in second position
	Topics *[][]common.Hash
}

BlockFilterCriteria encapsulates criteria passed to a `logs` accessor inside a block.

type BlockNumberArgs

type BlockNumberArgs struct {
	// TODO: Ideally we could use input unions to allow the query to specify the
	// block parameter by hash, block number, or tag but input unions aren't part of the
	// standard GraphQL schema SDL yet, see: https://github.com/graphql/graphql-spec/issues/488
	Block *hexutil.Uint64
}

BlockNumberArgs encapsulates arguments to accessors that specify a block number.

func (BlockNumberArgs) NumberOr

NumberOr returns the provided block number argument, or the "current" block number or hash if none was provided.

func (BlockNumberArgs) NumberOrLatest

func (a BlockNumberArgs) NumberOrLatest() rpc.BlockNumberOrHash

NumberOrLatest returns the provided block number argument, or the "latest" block number if none was provided.

type BlockType

type BlockType int

type Bytes

type Bytes []byte

Bytes marshals as a JSON string with \x prefix. The empty slice marshals as "\x".

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Bytes) String

func (b Bytes) String() string

String returns the hex encoding of b.

type CallData

type CallData struct {
	From     *common.Address // The Ethereum address the call is from.
	To       *common.Address // The Ethereum address the call is to.
	Gas      *hexutil.Uint64 // The amount of gas provided for the call.
	GasPrice *hexutil.Big    // The price of each unit of gas, in wei.
	Value    *hexutil.Big    // The value sent along with the call.
	Data     *hexutil.Bytes  // Any data sent with the call.
}

CallData encapsulates arguments to `call` or `estimateGas`. All arguments are optional.

type CallResult

type CallResult struct {
	// contains filtered or unexported fields
}

CallResult encapsulates the result of an invocation of the `call` accessor.

func (*CallResult) Data

func (c *CallResult) Data() hexutil.Bytes

func (*CallResult) GasUsed

func (c *CallResult) GasUsed() hexutil.Uint64

func (*CallResult) Status

func (c *CallResult) Status() hexutil.Uint64

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(endpoint string) *Client

func (*Client) AllEthHeaderCIDs

func (c *Client) AllEthHeaderCIDs(ctx context.Context, condition EthHeaderCIDCondition) (*AllEthHeaderCIDsResponse, error)

func (*Client) EthTransactionCIDByTxHash

func (c *Client) EthTransactionCIDByTxHash(ctx context.Context, txHash string) (*EthTransactionCIDResponse, error)

func (*Client) GetLogs

func (c *Client) GetLogs(ctx context.Context, hash common.Hash, addresses []common.Address) ([]LogResponse, error)

func (*Client) GetStorageAt

func (c *Client) GetStorageAt(ctx context.Context, hash common.Hash, address common.Address, slot string) (*StorageResponse, error)

type EthHeaderCID

type EthHeaderCID struct {
	// contains filtered or unexported fields
}

func (EthHeaderCID) BlockByMhKey

func (h EthHeaderCID) BlockByMhKey(ctx context.Context) IPFSBlock

func (EthHeaderCID) BlockHash

func (h EthHeaderCID) BlockHash(ctx context.Context) string

func (EthHeaderCID) BlockNumber

func (h EthHeaderCID) BlockNumber(ctx context.Context) BigInt

func (EthHeaderCID) Bloom

func (h EthHeaderCID) Bloom(ctx context.Context) string

func (EthHeaderCID) Cid

func (h EthHeaderCID) Cid(ctx context.Context) string

func (EthHeaderCID) EthTransactionCidsByHeaderId

func (h EthHeaderCID) EthTransactionCidsByHeaderId(ctx context.Context) EthTransactionCIDsConnection

func (EthHeaderCID) ParentHash

func (h EthHeaderCID) ParentHash(ctx context.Context) string

func (EthHeaderCID) ReceiptRoot

func (h EthHeaderCID) ReceiptRoot(ctx context.Context) string

func (EthHeaderCID) StateRoot

func (h EthHeaderCID) StateRoot(ctx context.Context) string

func (EthHeaderCID) Td

func (h EthHeaderCID) Td(ctx context.Context) BigInt

func (EthHeaderCID) Timestamp

func (h EthHeaderCID) Timestamp(ctx context.Context) BigInt

func (EthHeaderCID) TxRoot

func (h EthHeaderCID) TxRoot(ctx context.Context) string

func (EthHeaderCID) UncleRoot

func (h EthHeaderCID) UncleRoot(ctx context.Context) string

type EthHeaderCIDCondition

type EthHeaderCIDCondition struct {
	BlockNumber *BigInt
	BlockHash   *string
}

type EthHeaderCIDResponse

type EthHeaderCIDResponse struct {
	CID                          string                               `json:"cid"`
	BlockNumber                  BigInt                               `json:"blockNumber"`
	BlockHash                    string                               `json:"blockHash"`
	ParentHash                   string                               `json:"parentHash"`
	Timestamp                    BigInt                               `json:"timestamp"`
	StateRoot                    string                               `json:"stateRoot"`
	Td                           BigInt                               `json:"td"`
	TxRoot                       string                               `json:"txRoot"`
	ReceiptRoot                  string                               `json:"receiptRoot"`
	UncleRoot                    string                               `json:"uncleRoot"`
	Bloom                        string                               `json:"bloom"`
	EthTransactionCIDsByHeaderId EthTransactionCIDsByHeaderIdResponse `json:"ethTransactionCidsByHeaderId"`
	BlockByMhKey                 IPFSBlockResponse                    `json:"blockByMhKey"`
}

type EthHeaderCIDsConnection

type EthHeaderCIDsConnection struct {
	// contains filtered or unexported fields
}

func (EthHeaderCIDsConnection) Nodes

func (headerCIDResult EthHeaderCIDsConnection) Nodes(ctx context.Context) []*EthHeaderCID

type EthTransactionCID

type EthTransactionCID struct {
	// contains filtered or unexported fields
}

func (EthTransactionCID) BlockByMhKey

func (t EthTransactionCID) BlockByMhKey(ctx context.Context) IPFSBlock

func (EthTransactionCID) Cid

func (EthTransactionCID) Dst

func (EthTransactionCID) Index

func (t EthTransactionCID) Index(ctx context.Context) int32

func (EthTransactionCID) Src

func (EthTransactionCID) TxHash

func (t EthTransactionCID) TxHash(ctx context.Context) string

type EthTransactionCIDByTxHash

type EthTransactionCIDByTxHash struct {
	Response EthTransactionCIDResponse `json:"ethTransactionCidByTxHash"`
}

type EthTransactionCIDResponse

type EthTransactionCIDResponse struct {
	CID          string            `json:"cid"`
	TxHash       string            `json:"txHash"`
	Index        int32             `json:"index"`
	Src          string            `json:"src"`
	Dst          string            `json:"dst"`
	BlockByMhKey IPFSBlockResponse `json:"blockByMhKey"`
}

type EthTransactionCIDsByHeaderIdResponse

type EthTransactionCIDsByHeaderIdResponse struct {
	Nodes []EthTransactionCIDResponse `json:"nodes"`
}

type EthTransactionCIDsConnection

type EthTransactionCIDsConnection struct {
	// contains filtered or unexported fields
}

func (EthTransactionCIDsConnection) Nodes

func (transactionCIDResult EthTransactionCIDsConnection) Nodes(ctx context.Context) []*EthTransactionCID

type FilterCriteria

type FilterCriteria struct {
	FromBlock *hexutil.Uint64   // beginning of the queried range, nil means genesis block
	ToBlock   *hexutil.Uint64   // end of the range, nil means latest block
	Addresses *[]common.Address // restricts matches to events created by specific contracts

	// The Topic list restricts matches to particular event topics. Each event has a list
	// of topics. Topics matches a prefix of that list. An empty element slice matches any
	// topic. Non-empty elements represent an alternative that matches any of the
	// contained topics.
	//
	// Examples:
	// {} or nil          matches any topic list
	// {{A}}              matches topic A in first position
	// {{}, {B}}          matches any topic in first position, B in second position
	// {{A}, {B}}         matches topic A in first position, B in second position
	// {{A, B}}, {C, D}}  matches topic (A OR B) in first position, (C OR D) in second position
	Topics *[][]common.Hash
}

FilterCriteria encapsulates the arguments to `logs` on the root resolver object.

type GetLogs

type GetLogs struct {
	Responses []LogResponse `json:"getLogs"`
}

type GetStorageAt

type GetStorageAt struct {
	Response StorageResponse `json:"getStorageAt"`
}

type GraphiQL

type GraphiQL struct{}

GraphiQL is an in-browser IDE for exploring GraphiQL APIs. This handler returns GraphiQL when requested.

For more information, see https://github.com/graphql/graphiql.

func (GraphiQL) ServeHTTP

func (h GraphiQL) ServeHTTP(w http.ResponseWriter, r *http.Request)

type IPFSBlock

type IPFSBlock struct {
	// contains filtered or unexported fields
}

func (IPFSBlock) Data

func (b IPFSBlock) Data(ctx context.Context) string

func (IPFSBlock) Key

func (b IPFSBlock) Key(ctx context.Context) string

type IPFSBlockResponse

type IPFSBlockResponse struct {
	Key  string `json:"key"`
	Data string `json:"data"`
}

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log represents an individual log message. All arguments are mandatory.

func (*Log) Account

func (l *Log) Account(_ context.Context, args BlockNumberArgs) *Account

Account returns the contract account which generated this log.

func (*Log) Cid

func (l *Log) Cid(_ context.Context) string

Cid returns cid of the leaf node of this log.

func (*Log) Data

func (l *Log) Data(_ context.Context) hexutil.Bytes

Data returns data of this log.

func (*Log) Index

func (l *Log) Index(_ context.Context) int32

Index returns the index of this log in the block

func (*Log) IpldBlock

func (l *Log) IpldBlock(_ context.Context) hexutil.Bytes

IpldBlock returns IPLD block of the leaf node of this log.

func (*Log) ReceiptCID

func (l *Log) ReceiptCID(_ context.Context) string

ReceiptCID returns the receipt CID of the receipt IPLD block this Log exists in.

func (*Log) Status

func (l *Log) Status(_ context.Context) int32

Status returns the status of the receipt IPLD block this Log exists in.

func (*Log) Topics

func (l *Log) Topics(_ context.Context) []common.Hash

Topics returns the list of 0-4 indexed topics for the log.

func (*Log) Transaction

func (l *Log) Transaction(_ context.Context) *Transaction

Transaction returns transaction that generated this log entry.

type LogResponse

type LogResponse struct {
	Topics      []common.Hash       `json:"topics"`
	Data        hexutil.Bytes       `json:"data"`
	Transaction TransactionResponse `json:"transaction"`
	ReceiptCID  string              `json:"receiptCID"`
	Status      int32               `json:"status"`
}

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver is the top-level object in the GraphQL hierarchy.

func (*Resolver) AllEthHeaderCids

func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
	Condition *EthHeaderCIDCondition
}) (*EthHeaderCIDsConnection, error)

func (*Resolver) Block

func (r *Resolver) Block(ctx context.Context, args struct {
	Number *hexutil.Uint64
	Hash   *common.Hash
}) (*Block, error)

func (*Resolver) Blocks

func (r *Resolver) Blocks(ctx context.Context, args struct {
	From hexutil.Uint64
	To   *hexutil.Uint64
}) ([]*Block, error)

func (*Resolver) EthTransactionCidByTxHash

func (r *Resolver) EthTransactionCidByTxHash(ctx context.Context, args struct {
	TxHash      string
	BlockNumber *BigInt
}) (*EthTransactionCID, error)

func (*Resolver) GetLogs

func (r *Resolver) GetLogs(ctx context.Context, args struct {
	BlockHash   common.Hash
	BlockNumber *BigInt
	Addresses   *[]common.Address
}) (*[]*Log, error)

func (*Resolver) GetStorageAt

func (r *Resolver) GetStorageAt(ctx context.Context, args struct {
	BlockHash common.Hash
	Contract  common.Address
	Slot      common.Hash
}) (*StorageResult, error)

func (*Resolver) Logs

func (r *Resolver) Logs(ctx context.Context, args struct{ Filter FilterCriteria }) ([]*Log, error)

func (*Resolver) Transaction

func (r *Resolver) Transaction(ctx context.Context, args struct{ Hash common.Hash }) (*Transaction, error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service encapsulates a GraphQL service.

func New

func New(backend *eth.Backend, endpoint string, cors, vhosts []string, timeouts rpc.HTTPTimeouts) (*Service, error)

New constructs a new GraphQL service instance.

func (*Service) APIs

func (s *Service) APIs() []rpc.API

APIs returns the list of APIs exported by this service.

func (*Service) Protocols

func (s *Service) Protocols() []p2p.Protocol

Protocols returns the list of protocols exported by this service.

func (*Service) Start

func (s *Service) Start(server *p2p.Server) error

Start is called after all services have been constructed and the networking layer was also initialized to spawn any goroutines required by the service.

func (*Service) Stop

func (s *Service) Stop() error

Stop terminates all goroutines belonging to the service, blocking until they are all terminated.

type StorageResponse

type StorageResponse struct {
	CID       string        `json:"cid"`
	Value     common.Hash   `json:"value"`
	IpldBlock hexutil.Bytes `json:"ipldBlock"`
}

type StorageResult

type StorageResult struct {
	// contains filtered or unexported fields
}

StorageResult represents a storage slot value. All arguments are mandatory.

func (*StorageResult) Cid

func (s *StorageResult) Cid(ctx context.Context) string

func (*StorageResult) IpldBlock

func (s *StorageResult) IpldBlock(ctx context.Context) hexutil.Bytes

func (*StorageResult) Value

func (s *StorageResult) Value(ctx context.Context) common.Hash

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction represents an Ethereum transaction. backend and hash are mandatory; all others will be fetched when required.

func (*Transaction) Block

func (t *Transaction) Block(ctx context.Context) (*Block, error)

func (*Transaction) CreatedContract

func (t *Transaction) CreatedContract(ctx context.Context, args BlockNumberArgs) (*Account, error)

func (*Transaction) CumulativeGasUsed

func (t *Transaction) CumulativeGasUsed(ctx context.Context) (*hexutil.Uint64, error)

func (*Transaction) From

func (t *Transaction) From(ctx context.Context, args BlockNumberArgs) (*Account, error)

func (*Transaction) Gas

func (t *Transaction) Gas(ctx context.Context) (hexutil.Uint64, error)

func (*Transaction) GasPrice

func (t *Transaction) GasPrice(ctx context.Context) (hexutil.Big, error)

func (*Transaction) GasUsed

func (t *Transaction) GasUsed(ctx context.Context) (*hexutil.Uint64, error)

func (*Transaction) Hash

func (t *Transaction) Hash(ctx context.Context) common.Hash

func (*Transaction) Index

func (t *Transaction) Index(ctx context.Context) (*int32, error)

func (*Transaction) InputData

func (t *Transaction) InputData(ctx context.Context) (hexutil.Bytes, error)

func (*Transaction) Logs

func (t *Transaction) Logs(ctx context.Context) (*[]*Log, error)

func (*Transaction) Nonce

func (t *Transaction) Nonce(ctx context.Context) (hexutil.Uint64, error)

func (*Transaction) R

func (t *Transaction) R(ctx context.Context) (hexutil.Big, error)

func (*Transaction) S

func (t *Transaction) S(ctx context.Context) (hexutil.Big, error)

func (*Transaction) Status

func (t *Transaction) Status(ctx context.Context) (*hexutil.Uint64, error)

func (*Transaction) To

func (t *Transaction) To(ctx context.Context, args BlockNumberArgs) (*Account, error)

func (*Transaction) V

func (t *Transaction) V(ctx context.Context) (hexutil.Big, error)

func (*Transaction) Value

func (t *Transaction) Value(ctx context.Context) (hexutil.Big, error)

type TransactionResponse

type TransactionResponse struct {
	Hash common.Hash `json:"hash"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL