Skip to content

Commit 7f4a2ea

Browse files
authored
Revert "graphql: encode Long values as hex (ethereum#26894)"
This reverts commit c228163.
1 parent 7bb77d3 commit 7f4a2ea

File tree

3 files changed

+81
-78
lines changed

3 files changed

+81
-78
lines changed

graphql/graphql.go

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"math/big"
2525
"sort"
2626
"strconv"
27-
"strings"
2827
"sync"
2928

3029
"github.com/ethereum/go-ethereum"
@@ -55,16 +54,16 @@ func (b *Long) UnmarshalGraphQL(input interface{}) error {
5554
switch input := input.(type) {
5655
case string:
5756
// uncomment to support hex values
58-
if strings.HasPrefix(input, "0x") {
59-
// apply leniency and support hex representations of longs.
60-
value, err := hexutil.DecodeUint64(input)
61-
*b = Long(value)
62-
return err
63-
} else {
64-
value, err := strconv.ParseInt(input, 10, 64)
65-
*b = Long(value)
66-
return err
67-
}
57+
//if strings.HasPrefix(input, "0x") {
58+
// // apply leniency and support hex representations of longs.
59+
// value, err := hexutil.DecodeUint64(input)
60+
// *b = Long(value)
61+
// return err
62+
//} else {
63+
value, err := strconv.ParseInt(input, 10, 64)
64+
*b = Long(value)
65+
return err
66+
//}
6867
case int32:
6968
*b = Long(input)
7069
case int64:
@@ -157,8 +156,8 @@ func (l *Log) Account(ctx context.Context, args BlockNumberArgs) *Account {
157156
}
158157
}
159158

160-
func (l *Log) Index(ctx context.Context) hexutil.Uint64 {
161-
return hexutil.Uint64(l.log.Index)
159+
func (l *Log) Index(ctx context.Context) int32 {
160+
return int32(l.log.Index)
162161
}
163162

164163
func (l *Log) Topics(ctx context.Context) []common.Hash {
@@ -392,7 +391,7 @@ func (t *Transaction) Block(ctx context.Context) (*Block, error) {
392391
return block, nil
393392
}
394393

395-
func (t *Transaction) Index(ctx context.Context) (*hexutil.Uint64, error) {
394+
func (t *Transaction) Index(ctx context.Context) (*int32, error) {
396395
_, block, err := t.resolve(ctx)
397396
if err != nil {
398397
return nil, err
@@ -401,7 +400,7 @@ func (t *Transaction) Index(ctx context.Context) (*hexutil.Uint64, error) {
401400
if block == nil {
402401
return nil, nil
403402
}
404-
index := hexutil.Uint64(t.index)
403+
index := int32(t.index)
405404
return &index, nil
406405
}
407406

@@ -422,33 +421,33 @@ func (t *Transaction) getReceipt(ctx context.Context) (*types.Receipt, error) {
422421
return receipts[t.index], nil
423422
}
424423

425-
func (t *Transaction) Status(ctx context.Context) (*hexutil.Uint64, error) {
424+
func (t *Transaction) Status(ctx context.Context) (*Long, error) {
426425
receipt, err := t.getReceipt(ctx)
427426
if err != nil || receipt == nil {
428427
return nil, err
429428
}
430429
if len(receipt.PostState) != 0 {
431430
return nil, nil
432431
}
433-
ret := hexutil.Uint64(receipt.Status)
432+
ret := Long(receipt.Status)
434433
return &ret, nil
435434
}
436435

437-
func (t *Transaction) GasUsed(ctx context.Context) (*hexutil.Uint64, error) {
436+
func (t *Transaction) GasUsed(ctx context.Context) (*Long, error) {
438437
receipt, err := t.getReceipt(ctx)
439438
if err != nil || receipt == nil {
440439
return nil, err
441440
}
442-
ret := hexutil.Uint64(receipt.GasUsed)
441+
ret := Long(receipt.GasUsed)
443442
return &ret, nil
444443
}
445444

446-
func (t *Transaction) CumulativeGasUsed(ctx context.Context) (*hexutil.Uint64, error) {
445+
func (t *Transaction) CumulativeGasUsed(ctx context.Context) (*Long, error) {
447446
receipt, err := t.getReceipt(ctx)
448447
if err != nil || receipt == nil {
449448
return nil, err
450449
}
451-
ret := hexutil.Uint64(receipt.CumulativeGasUsed)
450+
ret := Long(receipt.CumulativeGasUsed)
452451
return &ret, nil
453452
}
454453

@@ -504,12 +503,12 @@ func (t *Transaction) getLogs(ctx context.Context, hash common.Hash) (*[]*Log, e
504503
return &ret, nil
505504
}
506505

507-
func (t *Transaction) Type(ctx context.Context) (*hexutil.Uint64, error) {
506+
func (t *Transaction) Type(ctx context.Context) (*int32, error) {
508507
tx, _, err := t.resolve(ctx)
509508
if err != nil {
510509
return nil, err
511510
}
512-
txType := hexutil.Uint64(tx.Type())
511+
txType := int32(tx.Type())
513512
return &txType, nil
514513
}
515514

@@ -650,13 +649,13 @@ func (b *Block) resolveReceipts(ctx context.Context) ([]*types.Receipt, error) {
650649
return receipts, nil
651650
}
652651

653-
func (b *Block) Number(ctx context.Context) (hexutil.Uint64, error) {
652+
func (b *Block) Number(ctx context.Context) (Long, error) {
654653
header, err := b.resolveHeader(ctx)
655654
if err != nil {
656655
return 0, err
657656
}
658657

659-
return hexutil.Uint64(header.Number.Uint64()), nil
658+
return Long(header.Number.Uint64()), nil
660659
}
661660

662661
func (b *Block) Hash(ctx context.Context) (common.Hash, error) {
@@ -665,20 +664,20 @@ func (b *Block) Hash(ctx context.Context) (common.Hash, error) {
665664
return b.hash, nil
666665
}
667666

668-
func (b *Block) GasLimit(ctx context.Context) (hexutil.Uint64, error) {
667+
func (b *Block) GasLimit(ctx context.Context) (Long, error) {
669668
header, err := b.resolveHeader(ctx)
670669
if err != nil {
671670
return 0, err
672671
}
673-
return hexutil.Uint64(header.GasLimit), nil
672+
return Long(header.GasLimit), nil
674673
}
675674

676-
func (b *Block) GasUsed(ctx context.Context) (hexutil.Uint64, error) {
675+
func (b *Block) GasUsed(ctx context.Context) (Long, error) {
677676
header, err := b.resolveHeader(ctx)
678677
if err != nil {
679678
return 0, err
680679
}
681-
return hexutil.Uint64(header.GasUsed), nil
680+
return Long(header.GasUsed), nil
682681
}
683682

684683
func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
@@ -794,12 +793,12 @@ func (b *Block) OmmerHash(ctx context.Context) (common.Hash, error) {
794793
return header.UncleHash, nil
795794
}
796795

797-
func (b *Block) OmmerCount(ctx context.Context) (*hexutil.Uint64, error) {
796+
func (b *Block) OmmerCount(ctx context.Context) (*int32, error) {
798797
block, err := b.resolve(ctx)
799798
if err != nil || block == nil {
800799
return nil, err
801800
}
802-
count := hexutil.Uint64(len(block.Uncles()))
801+
count := int32(len(block.Uncles()))
803802
return &count, err
804803
}
805804

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

876875
// NumberOr returns the provided block number argument, or the "current" block number or hash if none
@@ -901,12 +900,12 @@ func (b *Block) Miner(ctx context.Context, args BlockNumberArgs) (*Account, erro
901900
}, nil
902901
}
903902

904-
func (b *Block) TransactionCount(ctx context.Context) (*hexutil.Uint64, error) {
903+
func (b *Block) TransactionCount(ctx context.Context) (*int32, error) {
905904
block, err := b.resolve(ctx)
906905
if err != nil || block == nil {
907906
return nil, err
908907
}
909-
count := hexutil.Uint64(len(block.Transactions()))
908+
count := int32(len(block.Transactions()))
910909
return &count, err
911910
}
912911

@@ -928,7 +927,7 @@ func (b *Block) Transactions(ctx context.Context) (*[]*Transaction, error) {
928927
return &ret, nil
929928
}
930929

931-
func (b *Block) TransactionAt(ctx context.Context, args struct{ Index Long }) (*Transaction, error) {
930+
func (b *Block) TransactionAt(ctx context.Context, args struct{ Index int32 }) (*Transaction, error) {
932931
block, err := b.resolve(ctx)
933932
if err != nil || block == nil {
934933
return nil, err
@@ -947,7 +946,7 @@ func (b *Block) TransactionAt(ctx context.Context, args struct{ Index Long }) (*
947946
}, nil
948947
}
949948

950-
func (b *Block) OmmerAt(ctx context.Context, args struct{ Index Long }) (*Block, error) {
949+
func (b *Block) OmmerAt(ctx context.Context, args struct{ Index int32 }) (*Block, error) {
951950
block, err := b.resolve(ctx)
952951
if err != nil || block == nil {
953952
return nil, err
@@ -1038,7 +1037,7 @@ func (b *Block) Account(ctx context.Context, args struct {
10381037
type CallData struct {
10391038
From *common.Address // The Ethereum address the call is from.
10401039
To *common.Address // The Ethereum address the call is to.
1041-
Gas *Long // The amount of gas provided for the call.
1040+
Gas *hexutil.Uint64 // The amount of gas provided for the call.
10421041
GasPrice *hexutil.Big // The price of each unit of gas, in wei.
10431042
MaxFeePerGas *hexutil.Big // The max price of each unit of gas, in wei (1559).
10441043
MaxPriorityFeePerGas *hexutil.Big // The max tip of each unit of gas, in wei (1559).
@@ -1048,20 +1047,20 @@ type CallData struct {
10481047

10491048
// CallResult encapsulates the result of an invocation of the `call` accessor.
10501049
type CallResult struct {
1051-
data hexutil.Bytes // The return data from the call
1052-
gasUsed hexutil.Uint64 // The amount of gas used
1053-
status hexutil.Uint64 // The return status of the call - 0 for failure or 1 for success.
1050+
data hexutil.Bytes // The return data from the call
1051+
gasUsed Long // The amount of gas used
1052+
status Long // The return status of the call - 0 for failure or 1 for success.
10541053
}
10551054

10561055
func (c *CallResult) Data() hexutil.Bytes {
10571056
return c.data
10581057
}
10591058

1060-
func (c *CallResult) GasUsed() hexutil.Uint64 {
1059+
func (c *CallResult) GasUsed() Long {
10611060
return c.gasUsed
10621061
}
10631062

1064-
func (c *CallResult) Status() hexutil.Uint64 {
1063+
func (c *CallResult) Status() Long {
10651064
return c.status
10661065
}
10671066

@@ -1072,31 +1071,32 @@ func (b *Block) Call(ctx context.Context, args struct {
10721071
if err != nil {
10731072
return nil, err
10741073
}
1075-
status := hexutil.Uint64(1)
1074+
status := Long(1)
10761075
if result.Failed() {
10771076
status = 0
10781077
}
10791078

10801079
return &CallResult{
10811080
data: result.ReturnData,
1082-
gasUsed: hexutil.Uint64(result.UsedGas),
1081+
gasUsed: Long(result.UsedGas),
10831082
status: status,
10841083
}, nil
10851084
}
10861085

10871086
func (b *Block) EstimateGas(ctx context.Context, args struct {
10881087
Data ethapi.TransactionArgs
1089-
}) (hexutil.Uint64, error) {
1090-
return ethapi.DoEstimateGas(ctx, b.r.backend, args.Data, *b.numberOrHash, b.r.backend.RPCGasCap())
1088+
}) (Long, error) {
1089+
gas, err := ethapi.DoEstimateGas(ctx, b.r.backend, args.Data, *b.numberOrHash, b.r.backend.RPCGasCap())
1090+
return Long(gas), err
10911091
}
10921092

10931093
type Pending struct {
10941094
r *Resolver
10951095
}
10961096

1097-
func (p *Pending) TransactionCount(ctx context.Context) (hexutil.Uint64, error) {
1097+
func (p *Pending) TransactionCount(ctx context.Context) (int32, error) {
10981098
txs, err := p.r.backend.GetPoolTransactions()
1099-
return hexutil.Uint64(len(txs)), err
1099+
return int32(len(txs)), err
11001100
}
11011101

11021102
func (p *Pending) Transactions(ctx context.Context) (*[]*Transaction, error) {
@@ -1135,23 +1135,24 @@ func (p *Pending) Call(ctx context.Context, args struct {
11351135
if err != nil {
11361136
return nil, err
11371137
}
1138-
status := hexutil.Uint64(1)
1138+
status := Long(1)
11391139
if result.Failed() {
11401140
status = 0
11411141
}
11421142

11431143
return &CallResult{
11441144
data: result.ReturnData,
1145-
gasUsed: hexutil.Uint64(result.UsedGas),
1145+
gasUsed: Long(result.UsedGas),
11461146
status: status,
11471147
}, nil
11481148
}
11491149

11501150
func (p *Pending) EstimateGas(ctx context.Context, args struct {
11511151
Data ethapi.TransactionArgs
1152-
}) (hexutil.Uint64, error) {
1152+
}) (Long, error) {
11531153
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
1154-
return ethapi.DoEstimateGas(ctx, p.r.backend, args.Data, pendingBlockNr, p.r.backend.RPCGasCap())
1154+
gas, err := ethapi.DoEstimateGas(ctx, p.r.backend, args.Data, pendingBlockNr, p.r.backend.RPCGasCap())
1155+
return Long(gas), err
11551156
}
11561157

11571158
// Resolver is the top-level object in the GraphQL hierarchy.
@@ -1259,8 +1260,8 @@ func (r *Resolver) SendRawTransaction(ctx context.Context, args struct{ Data hex
12591260

12601261
// FilterCriteria encapsulates the arguments to `logs` on the root resolver object.
12611262
type FilterCriteria struct {
1262-
FromBlock *Long // beginning of the queried range, nil means genesis block
1263-
ToBlock *Long // end of the range, nil means latest block
1263+
FromBlock *hexutil.Uint64 // beginning of the queried range, nil means genesis block
1264+
ToBlock *hexutil.Uint64 // end of the range, nil means latest block
12641265
Addresses *[]common.Address // restricts matches to events created by specific contracts
12651266

12661267
// The Topic list restricts matches to particular event topics. Each event has a list

0 commit comments

Comments
 (0)