Skip to content

Commit 8514d66

Browse files
jsvisas1na
andauthored
graphql: add 4844 blob fields (#27963)
This adds block and receipt fields for EIP-4844. --------- Signed-off-by: jsvisa <[email protected]> Co-authored-by: Sina Mahmoodi <[email protected]>
1 parent 86bc2cd commit 8514d66

File tree

2 files changed

+126
-42
lines changed

2 files changed

+126
-42
lines changed

graphql/graphql.go

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,6 @@ func (t *Transaction) GasPrice(ctx context.Context) hexutil.Big {
272272
return hexutil.Big{}
273273
}
274274
switch tx.Type() {
275-
case types.AccessListTxType:
276-
return hexutil.Big(*tx.GasPrice())
277275
case types.DynamicFeeTxType:
278276
if block != nil {
279277
if baseFee, _ := block.BaseFeePerGas(ctx); baseFee != nil {
@@ -312,9 +310,7 @@ func (t *Transaction) MaxFeePerGas(ctx context.Context) *hexutil.Big {
312310
return nil
313311
}
314312
switch tx.Type() {
315-
case types.AccessListTxType:
316-
return nil
317-
case types.DynamicFeeTxType:
313+
case types.DynamicFeeTxType, types.BlobTxType:
318314
return (*hexutil.Big)(tx.GasFeeCap())
319315
default:
320316
return nil
@@ -327,15 +323,33 @@ func (t *Transaction) MaxPriorityFeePerGas(ctx context.Context) *hexutil.Big {
327323
return nil
328324
}
329325
switch tx.Type() {
330-
case types.AccessListTxType:
331-
return nil
332-
case types.DynamicFeeTxType:
326+
case types.DynamicFeeTxType, types.BlobTxType:
333327
return (*hexutil.Big)(tx.GasTipCap())
334328
default:
335329
return nil
336330
}
337331
}
338332

333+
func (t *Transaction) MaxFeePerBlobGas(ctx context.Context) *hexutil.Big {
334+
tx, _ := t.resolve(ctx)
335+
if tx == nil {
336+
return nil
337+
}
338+
return (*hexutil.Big)(tx.BlobGasFeeCap())
339+
}
340+
341+
func (t *Transaction) BlobVersionedHashes(ctx context.Context) *[]common.Hash {
342+
tx, _ := t.resolve(ctx)
343+
if tx == nil {
344+
return nil
345+
}
346+
if tx.Type() != types.BlobTxType {
347+
return nil
348+
}
349+
blobHashes := tx.BlobHashes()
350+
return &blobHashes
351+
}
352+
339353
func (t *Transaction) EffectiveTip(ctx context.Context) (*hexutil.Big, error) {
340354
tx, block := t.resolve(ctx)
341355
if tx == nil {
@@ -468,6 +482,40 @@ func (t *Transaction) CumulativeGasUsed(ctx context.Context) (*hexutil.Uint64, e
468482
return &ret, nil
469483
}
470484

485+
func (t *Transaction) BlobGasUsed(ctx context.Context) (*hexutil.Uint64, error) {
486+
tx, _ := t.resolve(ctx)
487+
if tx == nil {
488+
return nil, nil
489+
}
490+
if tx.Type() != types.BlobTxType {
491+
return nil, nil
492+
}
493+
494+
receipt, err := t.getReceipt(ctx)
495+
if err != nil || receipt == nil {
496+
return nil, err
497+
}
498+
ret := hexutil.Uint64(receipt.BlobGasUsed)
499+
return &ret, nil
500+
}
501+
502+
func (t *Transaction) BlobGasPrice(ctx context.Context) (*hexutil.Big, error) {
503+
tx, _ := t.resolve(ctx)
504+
if tx == nil {
505+
return nil, nil
506+
}
507+
if tx.Type() != types.BlobTxType {
508+
return nil, nil
509+
}
510+
511+
receipt, err := t.getReceipt(ctx)
512+
if err != nil || receipt == nil {
513+
return nil, err
514+
}
515+
ret := (*hexutil.Big)(receipt.BlobGasPrice)
516+
return ret, nil
517+
}
518+
471519
func (t *Transaction) CreatedContract(ctx context.Context, args BlockNumberArgs) (*Account, error) {
472520
receipt, err := t.getReceipt(ctx)
473521
if err != nil || receipt == nil || receipt.ContractAddress == (common.Address{}) {
@@ -1019,6 +1067,30 @@ func (b *Block) Withdrawals(ctx context.Context) (*[]*Withdrawal, error) {
10191067
return &ret, nil
10201068
}
10211069

1070+
func (b *Block) BlobGasUsed(ctx context.Context) (*hexutil.Uint64, error) {
1071+
header, err := b.resolveHeader(ctx)
1072+
if err != nil {
1073+
return nil, err
1074+
}
1075+
if header.BlobGasUsed == nil {
1076+
return nil, nil
1077+
}
1078+
ret := hexutil.Uint64(*header.BlobGasUsed)
1079+
return &ret, nil
1080+
}
1081+
1082+
func (b *Block) ExcessBlobGas(ctx context.Context) (*hexutil.Uint64, error) {
1083+
header, err := b.resolveHeader(ctx)
1084+
if err != nil {
1085+
return nil, err
1086+
}
1087+
if header.ExcessBlobGas == nil {
1088+
return nil, nil
1089+
}
1090+
ret := hexutil.Uint64(*header.ExcessBlobGas)
1091+
return &ret, nil
1092+
}
1093+
10221094
// BlockFilterCriteria encapsulates criteria passed to a `logs` accessor inside
10231095
// a block.
10241096
type BlockFilterCriteria struct {

graphql/schema.go

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ const schema string = `
7171
transaction: Transaction!
7272
}
7373
74-
#EIP-2718
75-
type AccessTuple{
74+
# EIP-2718
75+
type AccessTuple {
7676
address: Address!
7777
storageKeys : [Bytes32!]!
7878
}
@@ -112,6 +112,8 @@ const schema string = `
112112
maxFeePerGas: BigInt
113113
# MaxPriorityFeePerGas is the maximum miner tip per gas offered to include a transaction, in wei.
114114
maxPriorityFeePerGas: BigInt
115+
# MaxFeePerBlobGas is the maximum blob gas fee cap per blob the sender is willing to pay for blob transaction, in wei.
116+
maxFeePerBlobGas: BigInt
115117
# EffectiveTip is the actual amount of reward going to miner after considering the max fee cap.
116118
effectiveTip: BigInt
117119
# Gas is the maximum amount of gas this transaction can consume.
@@ -141,6 +143,10 @@ const schema string = `
141143
# coerced into the EIP-1559 format by setting both maxFeePerGas and
142144
# maxPriorityFeePerGas as the transaction's gas price.
143145
effectiveGasPrice: BigInt
146+
# BlobGasUsed is the amount of blob gas used by this transaction.
147+
blobGasUsed: Long
148+
# blobGasPrice is the actual value per blob gas deducted from the senders account.
149+
blobGasPrice: BigInt
144150
# CreatedContract is the account that was created by a contract creation
145151
# transaction. If the transaction was not a contract creation transaction,
146152
# or it has not yet been mined, this field will be null.
@@ -162,6 +168,8 @@ const schema string = `
162168
# RawReceipt is the canonical encoding of the receipt. For post EIP-2718 typed transactions
163169
# this is equivalent to TxType || ReceiptEncoding.
164170
rawReceipt: Bytes!
171+
# BlobVersionedHashes is a set of hash outputs from the blobs in the transaction.
172+
blobVersionedHashes: [Bytes32!]
165173
}
166174
167175
# BlockFilterCriteria encapsulates log filter criteria for a filter applied
@@ -171,16 +179,16 @@ const schema string = `
171179
# empty, results will not be filtered by address.
172180
addresses: [Address!]
173181
# Topics list restricts matches to particular event topics. Each event has a list
174-
# of topics. Topics matches a prefix of that list. An empty element array matches any
175-
# topic. Non-empty elements represent an alternative that matches any of the
176-
# contained topics.
177-
#
178-
# Examples:
179-
# - [] or nil matches any topic list
180-
# - [[A]] matches topic A in first position
181-
# - [[], [B]] matches any topic in first position, B in second position
182-
# - [[A], [B]] matches topic A in first position, B in second position
183-
# - [[A, B]], [C, D]] matches topic (A OR B) in first position, (C OR D) in second position
182+
# of topics. Topics matches a prefix of that list. An empty element array matches any
183+
# topic. Non-empty elements represent an alternative that matches any of the
184+
# contained topics.
185+
#
186+
# Examples:
187+
# - [] or nil matches any topic list
188+
# - [[A]] matches topic A in first position
189+
# - [[], [B]] matches any topic in first position, B in second position
190+
# - [[A], [B]] matches topic A in first position, B in second position
191+
# - [[A, B]], [C, D]] matches topic (A OR B) in first position, (C OR D) in second position
184192
topics: [[Bytes32!]!]
185193
}
186194
@@ -267,6 +275,10 @@ const schema string = `
267275
# Withdrawals is a list of withdrawals associated with this block. If
268276
# withdrawals are unavailable for this block, this field will be null.
269277
withdrawals: [Withdrawal!]
278+
# BlobGasUsed is the total amount of gas used by the transactions.
279+
blobGasUsed: Long
280+
# ExcessBlobGas is a running total of blob gas consumed in excess of the target, prior to the block.
281+
excessBlobGas: Long
270282
}
271283
272284
# CallData represents the data associated with a local contract call.
@@ -312,21 +324,21 @@ const schema string = `
312324
# empty, results will not be filtered by address.
313325
addresses: [Address!]
314326
# Topics list restricts matches to particular event topics. Each event has a list
315-
# of topics. Topics matches a prefix of that list. An empty element array matches any
316-
# topic. Non-empty elements represent an alternative that matches any of the
317-
# contained topics.
318-
#
319-
# Examples:
320-
# - [] or nil matches any topic list
321-
# - [[A]] matches topic A in first position
322-
# - [[], [B]] matches any topic in first position, B in second position
323-
# - [[A], [B]] matches topic A in first position, B in second position
324-
# - [[A, B]], [C, D]] matches topic (A OR B) in first position, (C OR D) in second position
327+
# of topics. Topics matches a prefix of that list. An empty element array matches any
328+
# topic. Non-empty elements represent an alternative that matches any of the
329+
# contained topics.
330+
#
331+
# Examples:
332+
# - [] or nil matches any topic list
333+
# - [[A]] matches topic A in first position
334+
# - [[], [B]] matches any topic in first position, B in second position
335+
# - [[A], [B]] matches topic A in first position, B in second position
336+
# - [[A, B]], [C, D]] matches topic (A OR B) in first position, (C OR D) in second position
325337
topics: [[Bytes32!]!]
326338
}
327339
328340
# SyncState contains the current synchronisation state of the client.
329-
type SyncState{
341+
type SyncState {
330342
# StartingBlock is the block number at which synchronisation started.
331343
startingBlock: Long!
332344
# CurrentBlock is the point at which synchronisation has presently reached.
@@ -337,17 +349,17 @@ const schema string = `
337349
338350
# Pending represents the current pending state.
339351
type Pending {
340-
# TransactionCount is the number of transactions in the pending state.
341-
transactionCount: Long!
342-
# Transactions is a list of transactions in the current pending state.
343-
transactions: [Transaction!]
344-
# Account fetches an Ethereum account for the pending state.
345-
account(address: Address!): Account!
346-
# Call executes a local call operation for the pending state.
347-
call(data: CallData!): CallResult
348-
# EstimateGas estimates the amount of gas that will be required for
349-
# successful execution of a transaction for the pending state.
350-
estimateGas(data: CallData!): Long!
352+
# TransactionCount is the number of transactions in the pending state.
353+
transactionCount: Long!
354+
# Transactions is a list of transactions in the current pending state.
355+
transactions: [Transaction!]
356+
# Account fetches an Ethereum account for the pending state.
357+
account(address: Address!): Account!
358+
# Call executes a local call operation for the pending state.
359+
call(data: CallData!): CallResult
360+
# EstimateGas estimates the amount of gas that will be required for
361+
# successful execution of a transaction for the pending state.
362+
estimateGas(data: CallData!): Long!
351363
}
352364
353365
type Query {

0 commit comments

Comments
 (0)