Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql: add raw fields to block and tx #24816

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 26 additions & 1 deletion graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
)

Expand Down Expand Up @@ -514,10 +515,18 @@ func (t *Transaction) V(ctx context.Context) (hexutil.Big, error) {
return hexutil.Big(*v), nil
}

func (t *Transaction) Raw(ctx context.Context) (hexutil.Bytes, error) {
tx, err := t.resolve(ctx)
if err != nil || tx == nil {
return hexutil.Bytes{}, err
}
return tx.MarshalBinary()
}

func (t *Transaction) RawReceipt(ctx context.Context) (hexutil.Bytes, error) {
receipt, err := t.getReceipt(ctx)
if err != nil || receipt == nil {
return nil, err
return hexutil.Bytes{}, err
}
return receipt.MarshalBinary()
}
Expand Down Expand Up @@ -796,6 +805,22 @@ func (b *Block) TotalDifficulty(ctx context.Context) (hexutil.Big, error) {
return hexutil.Big(*td), nil
}

func (b *Block) RawHeader(ctx context.Context) (hexutil.Bytes, error) {
header, err := b.resolveHeader(ctx)
if err != nil {
return hexutil.Bytes{}, err
}
return rlp.EncodeToBytes(header)
}

func (b *Block) Raw(ctx context.Context) (hexutil.Bytes, error) {
block, err := b.resolve(ctx)
if err != nil {
return hexutil.Bytes{}, err
}
return rlp.EncodeToBytes(block)
}

// BlockNumberArgs encapsulates arguments to accessors that specify a block number.
type BlockNumberArgs struct {
// TODO: Ideally we could use input unions to allow the query to specify the
Expand Down
10 changes: 9 additions & 1 deletion graphql/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ const schema string = `
# Envelope transaction support
type: Int
accessList: [AccessTuple!]
# RawReceipt is the binary encoding of the receipt. For post EIP-2718 typed transactions
# Raw is the canonical encoding of the transaction.
# For legacy transactions, it returns the RLP encoding.
# For EIP-2718 typed transactions, it returns the type and payload.
raw: Bytes!
# RawReceipt is the canonical encoding of the receipt. For post EIP-2718 typed transactions
# this is equivalent to TxType || ReceiptEncoding.
rawReceipt: Bytes!
}
Expand Down Expand Up @@ -238,6 +242,10 @@ const schema string = `
# EstimateGas estimates the amount of gas that will be required for
# successful execution of a transaction at the current block's state.
estimateGas(data: CallData!): Long!
# RawHeader is the RLP encoding of the block's header.
rawHeader: Bytes!
# Raw is the RLP encoding of the block.
raw: Bytes!
}

# CallData represents the data associated with a local contract call.
Expand Down