diff --git a/cmd/rpcdaemon/graphql/graph/generated.go b/cmd/rpcdaemon/graphql/graph/generated.go index a1b5953a4d9..74d6f0320c1 100644 --- a/cmd/rpcdaemon/graphql/graph/generated.go +++ b/cmd/rpcdaemon/graphql/graph/generated.go @@ -14,7 +14,6 @@ import ( "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" "github.com/erigontech/erigon/cmd/rpcdaemon/graphql/graph/model" - "github.com/erigontech/erigon/cmd/rpcdaemon/graphql/graph/scalar" gqlparser "github.com/vektah/gqlparser/v2" "github.com/vektah/gqlparser/v2/ast" ) @@ -31,11 +30,32 @@ type Config = graphql.Config[ResolverRoot, DirectiveRoot, ComplexityRoot] type ResolverRoot interface { Account() AccountResolver Block() BlockResolver + Log() LogResolver Mutation() MutationResolver Query() QueryResolver Transaction() TransactionResolver } +type AccountResolver interface { + Storage(ctx context.Context, obj *model.Account, slot string) (string, error) +} + +type BlockResolver interface { + Account(ctx context.Context, obj *model.Block, address string) (*model.Account, error) + Logs(ctx context.Context, obj *model.Block, filter model.BlockFilterCriteria) ([]*model.Log, error) + Miner(ctx context.Context, obj *model.Block, block *uint64) (*model.Account, error) +} + +type LogResolver interface { + Account(ctx context.Context, obj *model.Log, block *uint64) (*model.Account, error) +} + +type TransactionResolver interface { + CreatedContract(ctx context.Context, obj *model.Transaction, block *uint64) (*model.Account, error) + From(ctx context.Context, obj *model.Transaction, block *uint64) (*model.Account, error) + To(ctx context.Context, obj *model.Transaction, block *uint64) (*model.Account, error) +} + type DirectiveRoot struct { } @@ -56,11 +76,9 @@ type ComplexityRoot struct { Block struct { Account func(childComplexity int, address string) int BaseFeePerGas func(childComplexity int) int - BlobGasUsed func(childComplexity int) int Call func(childComplexity int, data model.CallData) int Difficulty func(childComplexity int) int EstimateGas func(childComplexity int, data model.CallData) int - ExcessBlobGas func(childComplexity int) int ExtraData func(childComplexity int) int GasLimit func(childComplexity int) int GasUsed func(childComplexity int) int @@ -82,13 +100,11 @@ type ComplexityRoot struct { ReceiptsRoot func(childComplexity int) int StateRoot func(childComplexity int) int Timestamp func(childComplexity int) int - TotalDifficulty func(childComplexity int) int TransactionAt func(childComplexity int, index int) int TransactionCount func(childComplexity int) int Transactions func(childComplexity int) int TransactionsRoot func(childComplexity int) int Withdrawals func(childComplexity int) int - WithdrawalsRoot func(childComplexity int) int } CallResult struct { @@ -119,7 +135,7 @@ type ComplexityRoot struct { Query struct { Block func(childComplexity int, number *string, hash *string) int - Blocks func(childComplexity int, from uint64, to *uint64) int + Blocks func(childComplexity int, from *uint64, to *uint64) int ChainID func(childComplexity int) int GasPrice func(childComplexity int) int Logs func(childComplexity int, filter model.FilterCriteria) int @@ -137,8 +153,6 @@ type ComplexityRoot struct { Transaction struct { AccessList func(childComplexity int) int - BlobGasPrice func(childComplexity int) int - BlobGasUsed func(childComplexity int) int Block func(childComplexity int) int CreatedContract func(childComplexity int, block *uint64) int CumulativeGasUsed func(childComplexity int) int @@ -152,7 +166,6 @@ type ComplexityRoot struct { Index func(childComplexity int) int InputData func(childComplexity int) int Logs func(childComplexity int) int - MaxFeePerBlobGas func(childComplexity int) int MaxFeePerGas func(childComplexity int) int MaxPriorityFeePerGas func(childComplexity int) int Nonce func(childComplexity int) int @@ -175,22 +188,12 @@ type ComplexityRoot struct { } } -type AccountResolver interface { - Storage(ctx context.Context, obj *model.Account, slot string) (string, error) -} -type BlockResolver interface { - TransactionAt(ctx context.Context, obj *model.Block, index int) (*model.Transaction, error) - Logs(ctx context.Context, obj *model.Block, filter model.BlockFilterCriteria) ([]*model.Log, error) - Account(ctx context.Context, obj *model.Block, address string) (*model.Account, error) - Call(ctx context.Context, obj *model.Block, data model.CallData) (*model.CallResult, error) - EstimateGas(ctx context.Context, obj *model.Block, data model.CallData) (uint64, error) -} type MutationResolver interface { SendRawTransaction(ctx context.Context, data string) (string, error) } type QueryResolver interface { Block(ctx context.Context, number *string, hash *string) (*model.Block, error) - Blocks(ctx context.Context, from uint64, to *uint64) ([]*model.Block, error) + Blocks(ctx context.Context, from *uint64, to *uint64) ([]*model.Block, error) Pending(ctx context.Context) (*model.Pending, error) Transaction(ctx context.Context, hash string) (*model.Transaction, error) Logs(ctx context.Context, filter model.FilterCriteria) ([]*model.Log, error) @@ -199,10 +202,6 @@ type QueryResolver interface { Syncing(ctx context.Context) (*model.SyncState, error) ChainID(ctx context.Context) (string, error) } -type TransactionResolver interface { - From(ctx context.Context, obj *model.Transaction, block *uint64) (*model.Account, error) - To(ctx context.Context, obj *model.Transaction, block *uint64) (*model.Account, error) -} type executableSchema graphql.ExecutableSchemaState[ResolverRoot, DirectiveRoot, ComplexityRoot] @@ -284,12 +283,6 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Block.BaseFeePerGas(childComplexity), true - case "Block.blobGasUsed": - if e.ComplexityRoot.Block.BlobGasUsed == nil { - break - } - - return e.ComplexityRoot.Block.BlobGasUsed(childComplexity), true case "Block.call": if e.ComplexityRoot.Block.Call == nil { break @@ -318,12 +311,6 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Block.EstimateGas(childComplexity, args["data"].(model.CallData)), true - case "Block.excessBlobGas": - if e.ComplexityRoot.Block.ExcessBlobGas == nil { - break - } - - return e.ComplexityRoot.Block.ExcessBlobGas(childComplexity), true case "Block.extraData": if e.ComplexityRoot.Block.ExtraData == nil { break @@ -465,12 +452,6 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Block.Timestamp(childComplexity), true - case "Block.totalDifficulty": - if e.ComplexityRoot.Block.TotalDifficulty == nil { - break - } - - return e.ComplexityRoot.Block.TotalDifficulty(childComplexity), true case "Block.transactionAt": if e.ComplexityRoot.Block.TransactionAt == nil { break @@ -506,12 +487,6 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Block.Withdrawals(childComplexity), true - case "Block.withdrawalsRoot": - if e.ComplexityRoot.Block.WithdrawalsRoot == nil { - break - } - - return e.ComplexityRoot.Block.WithdrawalsRoot(childComplexity), true case "CallResult.data": if e.ComplexityRoot.CallResult.Data == nil { @@ -647,7 +622,7 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return 0, false } - return e.ComplexityRoot.Query.Blocks(childComplexity, args["from"].(uint64), args["to"].(*uint64)), true + return e.ComplexityRoot.Query.Blocks(childComplexity, args["from"].(*uint64), args["to"].(*uint64)), true case "Query.chainID": if e.ComplexityRoot.Query.ChainID == nil { break @@ -727,18 +702,6 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Transaction.AccessList(childComplexity), true - case "Transaction.blobGasPrice": - if e.ComplexityRoot.Transaction.BlobGasPrice == nil { - break - } - - return e.ComplexityRoot.Transaction.BlobGasPrice(childComplexity), true - case "Transaction.blobGasUsed": - if e.ComplexityRoot.Transaction.BlobGasUsed == nil { - break - } - - return e.ComplexityRoot.Transaction.BlobGasUsed(childComplexity), true case "Transaction.block": if e.ComplexityRoot.Transaction.Block == nil { break @@ -827,12 +790,6 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Transaction.Logs(childComplexity), true - case "Transaction.maxFeePerBlobGas": - if e.ComplexityRoot.Transaction.MaxFeePerBlobGas == nil { - break - } - - return e.ComplexityRoot.Transaction.MaxFeePerBlobGas(childComplexity), true case "Transaction.maxFeePerGas": if e.ComplexityRoot.Transaction.MaxFeePerGas == nil { break @@ -1214,7 +1171,7 @@ func (ec *executionContext) field_Query_block_args(ctx context.Context, rawArgs func (ec *executionContext) field_Query_blocks_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} - arg0, err := graphql.ProcessArgField(ctx, rawArgs, "from", ec.unmarshalNLong2uint64) + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "from", ec.unmarshalOLong2ᚖuint64) if err != nil { return nil, err } @@ -1667,8 +1624,6 @@ func (ec *executionContext) fieldContext_Block_parent(_ context.Context, field g return ec.fieldContext_Block_mixHash(ctx, field) case "difficulty": return ec.fieldContext_Block_difficulty(ctx, field) - case "totalDifficulty": - return ec.fieldContext_Block_totalDifficulty(ctx, field) case "ommerCount": return ec.fieldContext_Block_ommerCount(ctx, field) case "ommers": @@ -1693,12 +1648,6 @@ func (ec *executionContext) fieldContext_Block_parent(_ context.Context, field g return ec.fieldContext_Block_rawHeader(ctx, field) case "raw": return ec.fieldContext_Block_raw(ctx, field) - case "withdrawalsRoot": - return ec.fieldContext_Block_withdrawalsRoot(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Block_blobGasUsed(ctx, field) - case "excessBlobGas": - return ec.fieldContext_Block_excessBlobGas(ctx, field) case "withdrawals": return ec.fieldContext_Block_withdrawals(ctx, field) } @@ -1776,7 +1725,7 @@ func (ec *executionContext) _Block_transactionCount(ctx context.Context, field g return obj.TransactionCount, nil }, nil, - ec.marshalOLong2ᚖuint64, + ec.marshalOInt2ᚖint, true, false, ) @@ -1789,7 +1738,7 @@ func (ec *executionContext) fieldContext_Block_transactionCount(_ context.Contex IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil @@ -1860,7 +1809,8 @@ func (ec *executionContext) _Block_miner(ctx context.Context, field graphql.Coll field, ec.fieldContext_Block_miner, func(ctx context.Context) (any, error) { - return obj.Miner, nil + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Block().Miner(ctx, obj, fc.Args["block"].(*uint64)) }, nil, ec.marshalNAccount2ᚖgithubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐAccount, @@ -1873,8 +1823,8 @@ func (ec *executionContext) fieldContext_Block_miner(ctx context.Context, field fc = &graphql.FieldContext{ Object: "Block", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "address": @@ -2166,35 +2116,6 @@ func (ec *executionContext) fieldContext_Block_difficulty(_ context.Context, fie return fc, nil } -func (ec *executionContext) _Block_totalDifficulty(ctx context.Context, field graphql.CollectedField, obj *model.Block) (ret graphql.Marshaler) { - return graphql.ResolveField( - ctx, - ec.OperationContext, - field, - ec.fieldContext_Block_totalDifficulty, - func(ctx context.Context) (any, error) { - return obj.TotalDifficulty, nil - }, - nil, - ec.marshalNBigInt2string, - true, - true, - ) -} - -func (ec *executionContext) fieldContext_Block_totalDifficulty(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Block", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type BigInt does not have child fields") - }, - } - return fc, nil -} - func (ec *executionContext) _Block_ommerCount(ctx context.Context, field graphql.CollectedField, obj *model.Block) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -2205,7 +2126,7 @@ func (ec *executionContext) _Block_ommerCount(ctx context.Context, field graphql return obj.OmmerCount, nil }, nil, - ec.marshalOLong2ᚖuint64, + ec.marshalOInt2ᚖint, true, false, ) @@ -2218,7 +2139,7 @@ func (ec *executionContext) fieldContext_Block_ommerCount(_ context.Context, fie IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil @@ -2284,8 +2205,6 @@ func (ec *executionContext) fieldContext_Block_ommers(_ context.Context, field g return ec.fieldContext_Block_mixHash(ctx, field) case "difficulty": return ec.fieldContext_Block_difficulty(ctx, field) - case "totalDifficulty": - return ec.fieldContext_Block_totalDifficulty(ctx, field) case "ommerCount": return ec.fieldContext_Block_ommerCount(ctx, field) case "ommers": @@ -2310,12 +2229,6 @@ func (ec *executionContext) fieldContext_Block_ommers(_ context.Context, field g return ec.fieldContext_Block_rawHeader(ctx, field) case "raw": return ec.fieldContext_Block_raw(ctx, field) - case "withdrawalsRoot": - return ec.fieldContext_Block_withdrawalsRoot(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Block_blobGasUsed(ctx, field) - case "excessBlobGas": - return ec.fieldContext_Block_excessBlobGas(ctx, field) case "withdrawals": return ec.fieldContext_Block_withdrawals(ctx, field) } @@ -2385,8 +2298,6 @@ func (ec *executionContext) fieldContext_Block_ommerAt(ctx context.Context, fiel return ec.fieldContext_Block_mixHash(ctx, field) case "difficulty": return ec.fieldContext_Block_difficulty(ctx, field) - case "totalDifficulty": - return ec.fieldContext_Block_totalDifficulty(ctx, field) case "ommerCount": return ec.fieldContext_Block_ommerCount(ctx, field) case "ommers": @@ -2411,12 +2322,6 @@ func (ec *executionContext) fieldContext_Block_ommerAt(ctx context.Context, fiel return ec.fieldContext_Block_rawHeader(ctx, field) case "raw": return ec.fieldContext_Block_raw(ctx, field) - case "withdrawalsRoot": - return ec.fieldContext_Block_withdrawalsRoot(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Block_blobGasUsed(ctx, field) - case "excessBlobGas": - return ec.fieldContext_Block_excessBlobGas(ctx, field) case "withdrawals": return ec.fieldContext_Block_withdrawals(ctx, field) } @@ -2542,12 +2447,6 @@ func (ec *executionContext) fieldContext_Block_transactions(_ context.Context, f return ec.fieldContext_Transaction_raw(ctx, field) case "rawReceipt": return ec.fieldContext_Transaction_rawReceipt(ctx, field) - case "maxFeePerBlobGas": - return ec.fieldContext_Transaction_maxFeePerBlobGas(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Transaction_blobGasUsed(ctx, field) - case "blobGasPrice": - return ec.fieldContext_Transaction_blobGasPrice(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Transaction", field.Name) }, @@ -2562,8 +2461,7 @@ func (ec *executionContext) _Block_transactionAt(ctx context.Context, field grap field, ec.fieldContext_Block_transactionAt, func(ctx context.Context) (any, error) { - fc := graphql.GetFieldContext(ctx) - return ec.Resolvers.Block().TransactionAt(ctx, obj, fc.Args["index"].(int)) + return obj.TransactionAt, nil }, nil, ec.marshalOTransaction2ᚖgithubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐTransaction, @@ -2576,8 +2474,8 @@ func (ec *executionContext) fieldContext_Block_transactionAt(ctx context.Context fc = &graphql.FieldContext{ Object: "Block", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "hash": @@ -2632,12 +2530,6 @@ func (ec *executionContext) fieldContext_Block_transactionAt(ctx context.Context return ec.fieldContext_Transaction_raw(ctx, field) case "rawReceipt": return ec.fieldContext_Transaction_rawReceipt(ctx, field) - case "maxFeePerBlobGas": - return ec.fieldContext_Transaction_maxFeePerBlobGas(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Transaction_blobGasUsed(ctx, field) - case "blobGasPrice": - return ec.fieldContext_Transaction_blobGasPrice(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Transaction", field.Name) }, @@ -2769,8 +2661,7 @@ func (ec *executionContext) _Block_call(ctx context.Context, field graphql.Colle field, ec.fieldContext_Block_call, func(ctx context.Context) (any, error) { - fc := graphql.GetFieldContext(ctx) - return ec.Resolvers.Block().Call(ctx, obj, fc.Args["data"].(model.CallData)) + return obj.Call, nil }, nil, ec.marshalOCallResult2ᚖgithubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐCallResult, @@ -2783,8 +2674,8 @@ func (ec *executionContext) fieldContext_Block_call(ctx context.Context, field g fc = &graphql.FieldContext{ Object: "Block", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "data": @@ -2818,8 +2709,7 @@ func (ec *executionContext) _Block_estimateGas(ctx context.Context, field graphq field, ec.fieldContext_Block_estimateGas, func(ctx context.Context) (any, error) { - fc := graphql.GetFieldContext(ctx) - return ec.Resolvers.Block().EstimateGas(ctx, obj, fc.Args["data"].(model.CallData)) + return obj.EstimateGas, nil }, nil, ec.marshalNLong2uint64, @@ -2832,8 +2722,8 @@ func (ec *executionContext) fieldContext_Block_estimateGas(ctx context.Context, fc = &graphql.FieldContext{ Object: "Block", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { return nil, errors.New("field of type Long does not have child fields") }, @@ -2910,93 +2800,6 @@ func (ec *executionContext) fieldContext_Block_raw(_ context.Context, field grap return fc, nil } -func (ec *executionContext) _Block_withdrawalsRoot(ctx context.Context, field graphql.CollectedField, obj *model.Block) (ret graphql.Marshaler) { - return graphql.ResolveField( - ctx, - ec.OperationContext, - field, - ec.fieldContext_Block_withdrawalsRoot, - func(ctx context.Context) (any, error) { - return obj.WithdrawalsRoot, nil - }, - nil, - ec.marshalOBytes322ᚖstring, - true, - false, - ) -} - -func (ec *executionContext) fieldContext_Block_withdrawalsRoot(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Block", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Bytes32 does not have child fields") - }, - } - return fc, nil -} - -func (ec *executionContext) _Block_blobGasUsed(ctx context.Context, field graphql.CollectedField, obj *model.Block) (ret graphql.Marshaler) { - return graphql.ResolveField( - ctx, - ec.OperationContext, - field, - ec.fieldContext_Block_blobGasUsed, - func(ctx context.Context) (any, error) { - return obj.BlobGasUsed, nil - }, - nil, - ec.marshalOLong2ᚖuint64, - true, - false, - ) -} - -func (ec *executionContext) fieldContext_Block_blobGasUsed(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Block", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") - }, - } - return fc, nil -} - -func (ec *executionContext) _Block_excessBlobGas(ctx context.Context, field graphql.CollectedField, obj *model.Block) (ret graphql.Marshaler) { - return graphql.ResolveField( - ctx, - ec.OperationContext, - field, - ec.fieldContext_Block_excessBlobGas, - func(ctx context.Context) (any, error) { - return obj.ExcessBlobGas, nil - }, - nil, - ec.marshalOLong2ᚖuint64, - true, - false, - ) -} - -func (ec *executionContext) fieldContext_Block_excessBlobGas(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Block", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") - }, - } - return fc, nil -} - func (ec *executionContext) _Block_withdrawals(ctx context.Context, field graphql.CollectedField, obj *model.Block) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -3133,7 +2936,7 @@ func (ec *executionContext) _Log_index(ctx context.Context, field graphql.Collec return obj.Index, nil }, nil, - ec.marshalNLong2uint64, + ec.marshalNInt2int, true, true, ) @@ -3146,7 +2949,7 @@ func (ec *executionContext) fieldContext_Log_index(_ context.Context, field grap IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil @@ -3159,7 +2962,8 @@ func (ec *executionContext) _Log_account(ctx context.Context, field graphql.Coll field, ec.fieldContext_Log_account, func(ctx context.Context) (any, error) { - return obj.Account, nil + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Log().Account(ctx, obj, fc.Args["block"].(*uint64)) }, nil, ec.marshalNAccount2ᚖgithubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐAccount, @@ -3172,8 +2976,8 @@ func (ec *executionContext) fieldContext_Log_account(ctx context.Context, field fc = &graphql.FieldContext{ Object: "Log", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "address": @@ -3338,12 +3142,6 @@ func (ec *executionContext) fieldContext_Log_transaction(_ context.Context, fiel return ec.fieldContext_Transaction_raw(ctx, field) case "rawReceipt": return ec.fieldContext_Transaction_rawReceipt(ctx, field) - case "maxFeePerBlobGas": - return ec.fieldContext_Transaction_maxFeePerBlobGas(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Transaction_blobGasUsed(ctx, field) - case "blobGasPrice": - return ec.fieldContext_Transaction_blobGasPrice(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Transaction", field.Name) }, @@ -3402,7 +3200,7 @@ func (ec *executionContext) _Pending_transactionCount(ctx context.Context, field return obj.TransactionCount, nil }, nil, - ec.marshalNLong2uint64, + ec.marshalNInt2int, true, true, ) @@ -3415,7 +3213,7 @@ func (ec *executionContext) fieldContext_Pending_transactionCount(_ context.Cont IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil @@ -3497,12 +3295,6 @@ func (ec *executionContext) fieldContext_Pending_transactions(_ context.Context, return ec.fieldContext_Transaction_raw(ctx, field) case "rawReceipt": return ec.fieldContext_Transaction_rawReceipt(ctx, field) - case "maxFeePerBlobGas": - return ec.fieldContext_Transaction_maxFeePerBlobGas(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Transaction_blobGasUsed(ctx, field) - case "blobGasPrice": - return ec.fieldContext_Transaction_blobGasPrice(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Transaction", field.Name) }, @@ -3711,8 +3503,6 @@ func (ec *executionContext) fieldContext_Query_block(ctx context.Context, field return ec.fieldContext_Block_mixHash(ctx, field) case "difficulty": return ec.fieldContext_Block_difficulty(ctx, field) - case "totalDifficulty": - return ec.fieldContext_Block_totalDifficulty(ctx, field) case "ommerCount": return ec.fieldContext_Block_ommerCount(ctx, field) case "ommers": @@ -3737,12 +3527,6 @@ func (ec *executionContext) fieldContext_Query_block(ctx context.Context, field return ec.fieldContext_Block_rawHeader(ctx, field) case "raw": return ec.fieldContext_Block_raw(ctx, field) - case "withdrawalsRoot": - return ec.fieldContext_Block_withdrawalsRoot(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Block_blobGasUsed(ctx, field) - case "excessBlobGas": - return ec.fieldContext_Block_excessBlobGas(ctx, field) case "withdrawals": return ec.fieldContext_Block_withdrawals(ctx, field) } @@ -3771,7 +3555,7 @@ func (ec *executionContext) _Query_blocks(ctx context.Context, field graphql.Col ec.fieldContext_Query_blocks, func(ctx context.Context) (any, error) { fc := graphql.GetFieldContext(ctx) - return ec.Resolvers.Query().Blocks(ctx, fc.Args["from"].(uint64), fc.Args["to"].(*uint64)) + return ec.Resolvers.Query().Blocks(ctx, fc.Args["from"].(*uint64), fc.Args["to"].(*uint64)) }, nil, ec.marshalNBlock2ᚕᚖgithubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐBlockᚄ, @@ -3824,8 +3608,6 @@ func (ec *executionContext) fieldContext_Query_blocks(ctx context.Context, field return ec.fieldContext_Block_mixHash(ctx, field) case "difficulty": return ec.fieldContext_Block_difficulty(ctx, field) - case "totalDifficulty": - return ec.fieldContext_Block_totalDifficulty(ctx, field) case "ommerCount": return ec.fieldContext_Block_ommerCount(ctx, field) case "ommers": @@ -3850,12 +3632,6 @@ func (ec *executionContext) fieldContext_Query_blocks(ctx context.Context, field return ec.fieldContext_Block_rawHeader(ctx, field) case "raw": return ec.fieldContext_Block_raw(ctx, field) - case "withdrawalsRoot": - return ec.fieldContext_Block_withdrawalsRoot(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Block_blobGasUsed(ctx, field) - case "excessBlobGas": - return ec.fieldContext_Block_excessBlobGas(ctx, field) case "withdrawals": return ec.fieldContext_Block_withdrawals(ctx, field) } @@ -3994,12 +3770,6 @@ func (ec *executionContext) fieldContext_Query_transaction(ctx context.Context, return ec.fieldContext_Transaction_raw(ctx, field) case "rawReceipt": return ec.fieldContext_Transaction_rawReceipt(ctx, field) - case "maxFeePerBlobGas": - return ec.fieldContext_Transaction_maxFeePerBlobGas(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Transaction_blobGasUsed(ctx, field) - case "blobGasPrice": - return ec.fieldContext_Transaction_blobGasPrice(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Transaction", field.Name) }, @@ -4458,7 +4228,7 @@ func (ec *executionContext) _Transaction_index(ctx context.Context, field graphq return obj.Index, nil }, nil, - ec.marshalOLong2ᚖuint64, + ec.marshalOInt2ᚖint, true, false, ) @@ -4471,7 +4241,7 @@ func (ec *executionContext) fieldContext_Transaction_index(_ context.Context, fi IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil @@ -4846,8 +4616,6 @@ func (ec *executionContext) fieldContext_Transaction_block(_ context.Context, fi return ec.fieldContext_Block_mixHash(ctx, field) case "difficulty": return ec.fieldContext_Block_difficulty(ctx, field) - case "totalDifficulty": - return ec.fieldContext_Block_totalDifficulty(ctx, field) case "ommerCount": return ec.fieldContext_Block_ommerCount(ctx, field) case "ommers": @@ -4872,12 +4640,6 @@ func (ec *executionContext) fieldContext_Transaction_block(_ context.Context, fi return ec.fieldContext_Block_rawHeader(ctx, field) case "raw": return ec.fieldContext_Block_raw(ctx, field) - case "withdrawalsRoot": - return ec.fieldContext_Block_withdrawalsRoot(ctx, field) - case "blobGasUsed": - return ec.fieldContext_Block_blobGasUsed(ctx, field) - case "excessBlobGas": - return ec.fieldContext_Block_excessBlobGas(ctx, field) case "withdrawals": return ec.fieldContext_Block_withdrawals(ctx, field) } @@ -5010,7 +4772,8 @@ func (ec *executionContext) _Transaction_createdContract(ctx context.Context, fi field, ec.fieldContext_Transaction_createdContract, func(ctx context.Context) (any, error) { - return obj.CreatedContract, nil + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Transaction().CreatedContract(ctx, obj, fc.Args["block"].(*uint64)) }, nil, ec.marshalOAccount2ᚖgithubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐAccount, @@ -5023,8 +4786,8 @@ func (ec *executionContext) fieldContext_Transaction_createdContract(ctx context fc = &graphql.FieldContext{ Object: "Transaction", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "address": @@ -5193,7 +4956,7 @@ func (ec *executionContext) _Transaction_type(ctx context.Context, field graphql return obj.Type, nil }, nil, - ec.marshalOLong2ᚖuint64, + ec.marshalOInt2ᚖint, true, false, ) @@ -5206,7 +4969,7 @@ func (ec *executionContext) fieldContext_Transaction_type(_ context.Context, fie IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil @@ -5305,93 +5068,6 @@ func (ec *executionContext) fieldContext_Transaction_rawReceipt(_ context.Contex return fc, nil } -func (ec *executionContext) _Transaction_maxFeePerBlobGas(ctx context.Context, field graphql.CollectedField, obj *model.Transaction) (ret graphql.Marshaler) { - return graphql.ResolveField( - ctx, - ec.OperationContext, - field, - ec.fieldContext_Transaction_maxFeePerBlobGas, - func(ctx context.Context) (any, error) { - return obj.MaxFeePerBlobGas, nil - }, - nil, - ec.marshalOBigInt2ᚖstring, - true, - false, - ) -} - -func (ec *executionContext) fieldContext_Transaction_maxFeePerBlobGas(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Transaction", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type BigInt does not have child fields") - }, - } - return fc, nil -} - -func (ec *executionContext) _Transaction_blobGasUsed(ctx context.Context, field graphql.CollectedField, obj *model.Transaction) (ret graphql.Marshaler) { - return graphql.ResolveField( - ctx, - ec.OperationContext, - field, - ec.fieldContext_Transaction_blobGasUsed, - func(ctx context.Context) (any, error) { - return obj.BlobGasUsed, nil - }, - nil, - ec.marshalOLong2ᚖuint64, - true, - false, - ) -} - -func (ec *executionContext) fieldContext_Transaction_blobGasUsed(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Transaction", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") - }, - } - return fc, nil -} - -func (ec *executionContext) _Transaction_blobGasPrice(ctx context.Context, field graphql.CollectedField, obj *model.Transaction) (ret graphql.Marshaler) { - return graphql.ResolveField( - ctx, - ec.OperationContext, - field, - ec.fieldContext_Transaction_blobGasPrice, - func(ctx context.Context) (any, error) { - return obj.BlobGasPrice, nil - }, - nil, - ec.marshalOBigInt2ᚖstring, - true, - false, - ) -} - -func (ec *executionContext) fieldContext_Transaction_blobGasPrice(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Transaction", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type BigInt does not have child fields") - }, - } - return fc, nil -} - func (ec *executionContext) _Withdrawal_index(ctx context.Context, field graphql.CollectedField, obj *model.Withdrawal) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -5402,7 +5078,7 @@ func (ec *executionContext) _Withdrawal_index(ctx context.Context, field graphql return obj.Index, nil }, nil, - ec.marshalNLong2uint64, + ec.marshalNInt2int, true, true, ) @@ -5415,7 +5091,7 @@ func (ec *executionContext) fieldContext_Withdrawal_index(_ context.Context, fie IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil @@ -5431,7 +5107,7 @@ func (ec *executionContext) _Withdrawal_validator(ctx context.Context, field gra return obj.Validator, nil }, nil, - ec.marshalNLong2uint64, + ec.marshalNInt2int, true, true, ) @@ -5444,7 +5120,7 @@ func (ec *executionContext) fieldContext_Withdrawal_validator(_ context.Context, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Long does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil @@ -7187,59 +6863,28 @@ func (ec *executionContext) _Account(ctx context.Context, sel ast.SelectionSet, case "address": out.Values[i] = ec._Account_address(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "balance": out.Values[i] = ec._Account_balance(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "transactionCount": out.Values[i] = ec._Account_transactionCount(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "code": out.Values[i] = ec._Account_code(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "storage": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Account_storage(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&fs.Invalids, 1) - } - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue + out.Values[i] = ec._Account_storage(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -7277,56 +6922,56 @@ func (ec *executionContext) _Block(ctx context.Context, sel ast.SelectionSet, ob case "number": out.Values[i] = ec._Block_number(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "hash": out.Values[i] = ec._Block_hash(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "parent": out.Values[i] = ec._Block_parent(ctx, field, obj) case "nonce": out.Values[i] = ec._Block_nonce(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "transactionsRoot": out.Values[i] = ec._Block_transactionsRoot(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "transactionCount": out.Values[i] = ec._Block_transactionCount(ctx, field, obj) case "stateRoot": out.Values[i] = ec._Block_stateRoot(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "receiptsRoot": out.Values[i] = ec._Block_receiptsRoot(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "miner": out.Values[i] = ec._Block_miner(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "extraData": out.Values[i] = ec._Block_extraData(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "gasLimit": out.Values[i] = ec._Block_gasLimit(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "gasUsed": out.Values[i] = ec._Block_gasUsed(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "baseFeePerGas": out.Values[i] = ec._Block_baseFeePerGas(ctx, field, obj) @@ -7335,27 +6980,22 @@ func (ec *executionContext) _Block(ctx context.Context, sel ast.SelectionSet, ob case "timestamp": out.Values[i] = ec._Block_timestamp(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "logsBloom": out.Values[i] = ec._Block_logsBloom(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "mixHash": out.Values[i] = ec._Block_mixHash(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "difficulty": out.Values[i] = ec._Block_difficulty(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) - } - case "totalDifficulty": - out.Values[i] = ec._Block_totalDifficulty(ctx, field, obj) - if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "ommerCount": out.Values[i] = ec._Block_ommerCount(ctx, field, obj) @@ -7366,200 +7006,39 @@ func (ec *executionContext) _Block(ctx context.Context, sel ast.SelectionSet, ob case "ommerHash": out.Values[i] = ec._Block_ommerHash(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "transactions": out.Values[i] = ec._Block_transactions(ctx, field, obj) case "transactionAt": - field := field - - innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Block_transactionAt(ctx, field, obj) - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue - } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + out.Values[i] = ec._Block_transactionAt(ctx, field, obj) case "logs": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Block_logs(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&fs.Invalids, 1) - } - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue + out.Values[i] = ec._Block_logs(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) case "account": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Block_account(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&fs.Invalids, 1) - } - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue + out.Values[i] = ec._Block_account(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) case "call": - field := field - - innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Block_call(ctx, field, obj) - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue - } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + out.Values[i] = ec._Block_call(ctx, field, obj) case "estimateGas": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Block_estimateGas(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&fs.Invalids, 1) - } - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue + out.Values[i] = ec._Block_estimateGas(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) case "rawHeader": out.Values[i] = ec._Block_rawHeader(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "raw": out.Values[i] = ec._Block_raw(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) - } - case "withdrawalsRoot": - out.Values[i] = ec._Block_withdrawalsRoot(ctx, field, obj) - case "blobGasUsed": - out.Values[i] = ec._Block_blobGasUsed(ctx, field, obj) - case "excessBlobGas": - out.Values[i] = ec._Block_excessBlobGas(ctx, field, obj) + out.Invalids++ + } case "withdrawals": out.Values[i] = ec._Block_withdrawals(ctx, field, obj) default: @@ -8097,93 +7576,31 @@ func (ec *executionContext) _Transaction(ctx context.Context, sel ast.SelectionS case "hash": out.Values[i] = ec._Transaction_hash(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "nonce": out.Values[i] = ec._Transaction_nonce(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "index": out.Values[i] = ec._Transaction_index(ctx, field, obj) case "from": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Transaction_from(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&fs.Invalids, 1) - } - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue + out.Values[i] = ec._Transaction_from(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) case "to": - field := field - - innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Transaction_to(ctx, field, obj) - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue - } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + out.Values[i] = ec._Transaction_to(ctx, field, obj) case "value": out.Values[i] = ec._Transaction_value(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "gasPrice": out.Values[i] = ec._Transaction_gasPrice(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "maxFeePerGas": out.Values[i] = ec._Transaction_maxFeePerGas(ctx, field, obj) @@ -8194,12 +7611,12 @@ func (ec *executionContext) _Transaction(ctx context.Context, sel ast.SelectionS case "gas": out.Values[i] = ec._Transaction_gas(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "inputData": out.Values[i] = ec._Transaction_inputData(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "block": out.Values[i] = ec._Transaction_block(ctx, field, obj) @@ -8218,17 +7635,17 @@ func (ec *executionContext) _Transaction(ctx context.Context, sel ast.SelectionS case "r": out.Values[i] = ec._Transaction_r(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "s": out.Values[i] = ec._Transaction_s(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "v": out.Values[i] = ec._Transaction_v(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "type": out.Values[i] = ec._Transaction_type(ctx, field, obj) @@ -8237,19 +7654,13 @@ func (ec *executionContext) _Transaction(ctx context.Context, sel ast.SelectionS case "raw": out.Values[i] = ec._Transaction_raw(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "rawReceipt": out.Values[i] = ec._Transaction_rawReceipt(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) - } - case "maxFeePerBlobGas": - out.Values[i] = ec._Transaction_maxFeePerBlobGas(ctx, field, obj) - case "blobGasUsed": - out.Values[i] = ec._Transaction_blobGasUsed(ctx, field, obj) - case "blobGasPrice": - out.Values[i] = ec._Transaction_blobGasPrice(ctx, field, obj) + out.Invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -8672,10 +8083,6 @@ func (ec *executionContext) marshalNAccessTuple2ᚖgithubᚗcomᚋerigontechᚋe return ec._AccessTuple(ctx, sel, v) } -func (ec *executionContext) marshalNAccount2githubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐAccount(ctx context.Context, sel ast.SelectionSet, v model.Account) graphql.Marshaler { - return ec._Account(ctx, sel, &v) -} - func (ec *executionContext) marshalNAccount2ᚖgithubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐAccount(ctx context.Context, sel ast.SelectionSet, v *model.Account) graphql.Marshaler { if v == nil { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { @@ -8880,13 +8287,13 @@ func (ec *executionContext) marshalNLog2ᚖgithubᚗcomᚋerigontechᚋerigonᚋ } func (ec *executionContext) unmarshalNLong2uint64(ctx context.Context, v any) (uint64, error) { - res, err := scalar.UnmarshalUint64(v) + res, err := graphql.UnmarshalUint64(v) return res, graphql.ErrorOnPath(ctx, err) } func (ec *executionContext) marshalNLong2uint64(ctx context.Context, sel ast.SelectionSet, v uint64) graphql.Marshaler { _ = sel - res := scalar.MarshalUint64(v) + res := graphql.MarshalUint64(v) if res == graphql.Null { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { graphql.AddErrorf(ctx, "the requested element is null which the schema does not allow") @@ -9331,6 +8738,24 @@ func (ec *executionContext) marshalOCallResult2ᚖgithubᚗcomᚋerigontechᚋer return ec._CallResult(ctx, sel, v) } +func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v any) (*int, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalInt(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.SelectionSet, v *int) graphql.Marshaler { + if v == nil { + return graphql.Null + } + _ = sel + _ = ctx + res := graphql.MarshalInt(*v) + return res +} + func (ec *executionContext) marshalOLog2ᚕᚖgithubᚗcomᚋerigontechᚋerigonᚋcmdᚋrpcdaemonᚋgraphqlᚋgraphᚋmodelᚐLogᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Log) graphql.Marshaler { if v == nil { return graphql.Null @@ -9354,7 +8779,7 @@ func (ec *executionContext) unmarshalOLong2ᚖuint64(ctx context.Context, v any) if v == nil { return nil, nil } - res, err := scalar.UnmarshalUint64(v) + res, err := graphql.UnmarshalUint64(v) return &res, graphql.ErrorOnPath(ctx, err) } @@ -9364,7 +8789,7 @@ func (ec *executionContext) marshalOLong2ᚖuint64(ctx context.Context, sel ast. } _ = sel _ = ctx - res := scalar.MarshalUint64(*v) + res := graphql.MarshalUint64(*v) return res } diff --git a/cmd/rpcdaemon/graphql/graph/resolver_helpers.go b/cmd/rpcdaemon/graphql/graph/resolver_helpers.go index 196896f76ef..4de9619714d 100644 --- a/cmd/rpcdaemon/graphql/graph/resolver_helpers.go +++ b/cmd/rpcdaemon/graphql/graph/resolver_helpers.go @@ -2,6 +2,8 @@ package graph import ( "context" + "fmt" + "math" "strings" "github.com/erigontech/erigon/cmd/rpcdaemon/graphql/graph/model" @@ -12,12 +14,18 @@ import ( ) func (r *Resolver) resolveAccountAtBlock(ctx context.Context, address string, defaultBlock uint64, override *uint64) (*model.Account, error) { - blockNum := rpc.BlockNumber(defaultBlock) + blockNum := defaultBlock if override != nil { - blockNum = rpc.BlockNumber(*override) + blockNum = *override + } + if !common.IsHexAddress(address) { + return nil, fmt.Errorf("invalid address %q", address) + } + if blockNum > uint64(math.MaxInt64) { + return nil, fmt.Errorf("block number %d exceeds max supported value", blockNum) } addr := common.HexToAddress(address) - balance, nonce, code, err := r.GraphQLAPI.GetAccountInfo(ctx, addr, blockNum) + balance, nonce, code, err := r.GraphQLAPI.GetAccountInfo(ctx, addr, rpc.BlockNumber(blockNum)) if err != nil { return nil, err } @@ -26,10 +34,74 @@ func (r *Resolver) resolveAccountAtBlock(ctx context.Context, address string, de Balance: balance, TransactionCount: nonce, Code: code, - BlockNum: uint64(blockNum), + BlockNum: blockNum, }, nil } +func (r *Resolver) resolveAccountAtRequestedBlock(ctx context.Context, account *model.Account, block *uint64) (*model.Account, error) { + if account == nil || account.Address == "" { + return nil, nil + } + return r.resolveAccountAtBlock(ctx, account.Address, account.BlockNum, block) +} + +func normalizeHex(value string) string { + return strings.ToLower(value) +} + +func flattenBlockLogs(transactions []*model.Transaction) []*model.Log { + var logs []*model.Log + for _, tx := range transactions { + if tx == nil { + continue + } + logs = append(logs, tx.Logs...) + } + return logs +} + +func blockLogMatchesFilter(log *model.Log, filter model.BlockFilterCriteria) bool { + if log == nil { + return false + } + + if len(filter.Addresses) > 0 { + if log.Account == nil || log.Account.Address == "" { + return false + } + match := false + for _, address := range filter.Addresses { + if normalizeHex(address) == normalizeHex(log.Account.Address) { + match = true + break + } + } + if !match { + return false + } + } + + for i, alternatives := range filter.Topics { + if len(alternatives) == 0 { + continue + } + if i >= len(log.Topics) { + return false + } + match := false + for _, topic := range alternatives { + if normalizeHex(topic) == normalizeHex(log.Topics[i]) { + match = true + break + } + } + if !match { + return false + } + } + return true +} + func (r *queryResolver) buildBlock(res map[string]any) (*model.Block, error) { block := &model.Block{} absBlk := res["block"] diff --git a/cmd/rpcdaemon/graphql/graph/schema.graphqls b/cmd/rpcdaemon/graphql/graph/schema.graphqls index 9a2b936f96e..623f3ed60c0 100644 --- a/cmd/rpcdaemon/graphql/graph/schema.graphqls +++ b/cmd/rpcdaemon/graphql/graph/schema.graphqls @@ -14,6 +14,16 @@ scalar Long # Either a string or an unsigned int scalar BlockNum +directive @goField( + forceResolver: Boolean + name: String + omittable: Boolean + type: String + autoBindGetterHaser: Boolean + forceGenerate: Boolean + batch: Boolean +) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION + schema { query: Query mutation: Mutation @@ -34,7 +44,7 @@ type Account { code: Bytes! # Storage provides access to the storage of a contract account, indexed # by its 32 byte slot identifier. - storage(slot: Bytes32!): Bytes32! + storage(slot: Bytes32!): Bytes32! @goField(forceResolver: true) } # Log is an Ethereum event log. @@ -43,7 +53,7 @@ type Log { index: Long! # Account is the account which generated this log - this will always # be a contract account. - account(block: Long): Account! + account(block: Long): Account! @goField(forceResolver: true) # Topics is a list of 0-4 indexed topics for the log. topics: [Bytes32!]! # Data is unindexed data for this log. @@ -69,10 +79,10 @@ type Transaction { index: Long # From is the account that sent this transaction - this will always be # an externally owned account. - from(block: Long): Account! + from(block: Long): Account! @goField(forceResolver: true) # To is the account the transaction was sent to. This is null for # contract-creating transactions. - to(block: Long): Account + to(block: Long): Account @goField(forceResolver: true) # Value is the value, in wei, sent along with this transaction. value: BigInt! # GasPrice is the price offered to miners for gas, in wei per unit. @@ -113,7 +123,7 @@ type Transaction { # CreatedContract is the account that was created by a contract creation # transaction. If the transaction was not a contract creation transaction, # or it has not yet been mined, this field will be null. - createdContract(block: Long): Account + createdContract(block: Long): Account @goField(forceResolver: true) # Logs is a list of log entries emitted by this transaction. If the # transaction has not yet been mined, this field will be null. logs: [Log!] @@ -178,7 +188,7 @@ type Block { # ReceiptsRoot is the keccak256 hash of the trie of transaction receipts in this block. receiptsRoot: Bytes32! # Miner is the account that mined this block. - miner(block: Long): Account! + miner(block: Long): Account! @goField(forceResolver: true) # ExtraData is an arbitrary data field supplied by the miner. extraData: Bytes! # GasLimit is the maximum amount of gas that was available to transactions in this block. @@ -222,9 +232,9 @@ type Block { # bounds, this field will be null. transactionAt(index: Int!): Transaction # Logs returns a filtered set of logs from this block. - logs(filter: BlockFilterCriteria!): [Log!]! + logs(filter: BlockFilterCriteria!): [Log!]! @goField(forceResolver: true) # Account fetches an Ethereum account at the current block's state. - account(address: Address!): Account! + account(address: Address!): Account! @goField(forceResolver: true) # Call executes a local call operation at the current block's state. call(data: CallData!): CallResult # EstimateGas estimates the amount of gas that will be required for diff --git a/cmd/rpcdaemon/graphql/graph/schema.resolvers.go b/cmd/rpcdaemon/graphql/graph/schema.resolvers.go index 9cb0f2f5c1b..d2d7f2ed6ee 100644 --- a/cmd/rpcdaemon/graphql/graph/schema.resolvers.go +++ b/cmd/rpcdaemon/graphql/graph/schema.resolvers.go @@ -8,6 +8,7 @@ package graph import ( "context" "fmt" + "math" "strconv" "github.com/erigontech/erigon/cmd/rpcdaemon/graphql/graph/model" @@ -18,7 +19,9 @@ import ( // Storage is the resolver for the storage field. func (r *accountResolver) Storage(ctx context.Context, obj *model.Account, slot string) (string, error) { - panic("not implemented: Storage - storage") + addr := common.HexToAddress(obj.Address) + blockNumber := rpc.BlockNumber(obj.BlockNum) + return r.GraphQLAPI.GetAccountStorage(ctx, addr, slot, blockNumber) } // TransactionAt is the resolver for the transactionAt field. @@ -31,7 +34,21 @@ func (r *blockResolver) TransactionAt(ctx context.Context, obj *model.Block, ind // Logs is the resolver for the logs field. func (r *blockResolver) Logs(ctx context.Context, obj *model.Block, filter model.BlockFilterCriteria) ([]*model.Log, error) { - panic("not implemented: Logs - logs") + logs := obj.Logs + if logs == nil { + logs = flattenBlockLogs(obj.Transactions) + } + if len(logs) == 0 { + return []*model.Log{}, nil + } + + filtered := make([]*model.Log, 0, len(logs)) + for _, log := range logs { + if blockLogMatchesFilter(log, filter) { + filtered = append(filtered, log) + } + } + return filtered, ctx.Err() } // Account is the resolver for the account field. @@ -52,6 +69,15 @@ func (r *blockResolver) EstimateGas(ctx context.Context, obj *model.Block, data panic("not implemented: EstimateGas - estimateGas") } +// Miner is the resolver for the miner field. +func (r *blockResolver) Miner(ctx context.Context, obj *model.Block, block *uint64) (*model.Account, error) { + account, err := r.resolveAccountAtRequestedBlock(ctx, obj.Miner, block) + if account != nil || err != nil { + return account, err + } + return nil, fmt.Errorf("block miner is unavailable") +} + // SendRawTransaction is the resolver for the sendRawTransaction field. func (r *mutationResolver) SendRawTransaction(ctx context.Context, data string) (string, error) { panic("not implemented: SendRawTransaction - sendRawTransaction") @@ -80,10 +106,16 @@ func (r *queryResolver) Block(ctx context.Context, number *string, hash *string) if number != nil { bNum, err := strconv.ParseUint(*number, 10, 64) if err == nil { + if bNum > uint64(math.MaxInt64) { + return nil, fmt.Errorf("block number %d exceeds max supported value", bNum) + } blockNumber = rpc.BlockNumber(bNum) } else { bNum, err := hexutil.DecodeUint64(*number) if err == nil { + if bNum > uint64(math.MaxInt64) { + return nil, fmt.Errorf("block number %d exceeds max supported value", bNum) + } blockNumber = rpc.BlockNumber(bNum) } else { return nil, fmt.Errorf("invalid block number: %s", *number) @@ -104,8 +136,11 @@ func (r *queryResolver) Block(ctx context.Context, number *string, hash *string) } // Blocks is the resolver for the blocks field. -func (r *queryResolver) Blocks(ctx context.Context, from uint64, to *uint64) ([]*model.Block, error) { - fromBlockNumber := from +func (r *queryResolver) Blocks(ctx context.Context, from *uint64, to *uint64) ([]*model.Block, error) { + if from == nil { + return nil, &rpc.InvalidParamsError{Message: "Invalid params"} + } + fromBlockNumber := *from var toBlockNumber uint64 if to != nil { @@ -211,18 +246,30 @@ func (r *queryResolver) ChainID(ctx context.Context) (string, error) { // From is the resolver for the from field. func (r *transactionResolver) From(ctx context.Context, obj *model.Transaction, block *uint64) (*model.Account, error) { - if obj.From == nil { - return nil, nil + account, err := r.resolveAccountAtRequestedBlock(ctx, obj.From, block) + if account != nil || err != nil { + return account, err } - return r.resolveAccountAtBlock(ctx, obj.From.Address, obj.Block.Number, block) + return nil, fmt.Errorf("transaction sender is unavailable") } // To is the resolver for the to field. func (r *transactionResolver) To(ctx context.Context, obj *model.Transaction, block *uint64) (*model.Account, error) { - if obj.To == nil { - return nil, nil + return r.resolveAccountAtRequestedBlock(ctx, obj.To, block) +} + +// Account is the resolver for the account field. +func (r *logResolver) Account(ctx context.Context, obj *model.Log, block *uint64) (*model.Account, error) { + account, err := r.resolveAccountAtRequestedBlock(ctx, obj.Account, block) + if account != nil || err != nil { + return account, err } - return r.resolveAccountAtBlock(ctx, obj.To.Address, obj.Block.Number, block) + return nil, fmt.Errorf("log account is unavailable") +} + +// CreatedContract is the resolver for the createdContract field. +func (r *transactionResolver) CreatedContract(ctx context.Context, obj *model.Transaction, block *uint64) (*model.Account, error) { + return r.resolveAccountAtRequestedBlock(ctx, obj.CreatedContract, block) } // Account returns AccountResolver implementation. @@ -237,11 +284,15 @@ func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} } // Query returns QueryResolver implementation. func (r *Resolver) Query() QueryResolver { return &queryResolver{r} } +// Log returns LogResolver implementation. +func (r *Resolver) Log() LogResolver { return &logResolver{r} } + // Transaction returns TransactionResolver implementation. func (r *Resolver) Transaction() TransactionResolver { return &transactionResolver{r} } type accountResolver struct{ *Resolver } type blockResolver struct{ *Resolver } +type logResolver struct{ *Resolver } type mutationResolver struct{ *Resolver } type queryResolver struct{ *Resolver } type transactionResolver struct{ *Resolver } diff --git a/cmd/rpcdaemon/graphql/graph/schema_resolvers_test.go b/cmd/rpcdaemon/graphql/graph/schema_resolvers_test.go index 0ac1715fe59..d017beb023a 100644 --- a/cmd/rpcdaemon/graphql/graph/schema_resolvers_test.go +++ b/cmd/rpcdaemon/graphql/graph/schema_resolvers_test.go @@ -18,11 +18,50 @@ package graph import ( "context" + "math" + "math/big" "testing" "github.com/erigontech/erigon/cmd/rpcdaemon/graphql/graph/model" + "github.com/erigontech/erigon/common" + "github.com/erigontech/erigon/rpc" ) +type mockGraphQLAPI struct { + getAccountInfo func(ctx context.Context, address common.Address, blockNumber rpc.BlockNumber) (string, uint64, string, error) +} + +func (m mockGraphQLAPI) GetBlockDetails(context.Context, rpc.BlockNumber) (map[string]any, error) { + return nil, nil +} + +func (m mockGraphQLAPI) GetBlockDetailsByHash(context.Context, common.Hash) (map[string]any, error) { + return nil, nil +} + +func (m mockGraphQLAPI) GetLatestBlockNumber(context.Context) (uint64, error) { + return 0, nil +} + +func (m mockGraphQLAPI) GetChainID(context.Context) (*big.Int, error) { + return big.NewInt(1), nil +} + +func (m mockGraphQLAPI) GetAccountInfo(ctx context.Context, address common.Address, blockNumber rpc.BlockNumber) (string, uint64, string, error) { + if m.getAccountInfo != nil { + return m.getAccountInfo(ctx, address, blockNumber) + } + return "0x0", 0, "0x", nil +} + +func (m mockGraphQLAPI) GetAccountStorage(context.Context, common.Address, string, rpc.BlockNumber) (string, error) { + return "0x0", nil +} + +func (m mockGraphQLAPI) GetBlockNumberForTx(context.Context, common.Hash) (uint64, bool, error) { + return 0, false, nil +} + // TestBlockResolver_Account_InvalidAddress verifies that a malformed address // string is rejected before any GraphQL API call is made. func TestBlockResolver_Account_InvalidAddress(t *testing.T) { @@ -59,6 +98,188 @@ func TestNewAccountAtBlock(t *testing.T) { } } +func TestBlockResolverLogsAppliesFilter(t *testing.T) { + block := &model.Block{ + Logs: []*model.Log{ + { + Index: 0, + Account: &model.Account{Address: "0x1111111111111111111111111111111111111111"}, + Topics: []string{ + "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + }, + }, + { + Index: 1, + Account: &model.Account{Address: "0x2222222222222222222222222222222222222222"}, + Topics: []string{ + "0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + }, + }, + }, + } + + resolver := &blockResolver{&Resolver{}} + logs, err := resolver.Logs(context.Background(), block, model.BlockFilterCriteria{ + Addresses: []string{"0x1111111111111111111111111111111111111111"}, + Topics: [][]string{ + {"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, + {"0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"}, + }, + }) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if len(logs) != 1 { + t.Fatalf("expected 1 log, got %d", len(logs)) + } + if logs[0].Index != 0 { + t.Fatalf("expected first log to match, got index %d", logs[0].Index) + } +} + +func TestBlockResolverLogsTopicWildcardDoesNotRequireTopicPosition(t *testing.T) { + block := &model.Block{ + Logs: []*model.Log{ + { + Index: 0, + Topics: []string{ + "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + }, + }, + }, + } + + resolver := &blockResolver{&Resolver{}} + logs, err := resolver.Logs(context.Background(), block, model.BlockFilterCriteria{ + Topics: [][]string{ + {"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, + {}, + }, + }) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if len(logs) != 1 { + t.Fatalf("expected 1 log, got %d", len(logs)) + } +} + +func TestBlockResolverLogsFallsBackToFlattenTransactionsWhenLogsNil(t *testing.T) { + block := &model.Block{ + Logs: nil, + Transactions: []*model.Transaction{ + { + Logs: []*model.Log{ + {Index: 7}, + }, + }, + }, + } + + resolver := &blockResolver{&Resolver{}} + logs, err := resolver.Logs(context.Background(), block, model.BlockFilterCriteria{}) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if len(logs) != 1 { + t.Fatalf("expected 1 flattened log, got %d", len(logs)) + } + if logs[0].Index != 7 { + t.Fatalf("expected flattened log index 7, got %d", logs[0].Index) + } +} + +func TestTransactionResolverFromUsesRequestedBlock(t *testing.T) { + const address = "0x1111111111111111111111111111111111111111" + + var gotAddress common.Address + var gotBlock rpc.BlockNumber + + resolver := &transactionResolver{&Resolver{ + GraphQLAPI: mockGraphQLAPI{ + getAccountInfo: func(_ context.Context, addr common.Address, blockNumber rpc.BlockNumber) (string, uint64, string, error) { + gotAddress = addr + gotBlock = blockNumber + return "0x10", 7, "0x6000", nil + }, + }, + }} + + tx := &model.Transaction{From: model.NewAccountAtBlock(12)} + tx.From.Address = address + targetBlock := uint64(99) + + account, err := resolver.From(context.Background(), tx, &targetBlock) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if gotAddress != common.HexToAddress(address) { + t.Fatalf("expected address %s, got %s", address, gotAddress) + } + if gotBlock != rpc.BlockNumber(targetBlock) { + t.Fatalf("expected block %d, got %d", targetBlock, gotBlock) + } + if account.BlockNum != targetBlock { + t.Fatalf("expected result block %d, got %d", targetBlock, account.BlockNum) + } +} + +func TestLogResolverAccountFallsBackToEmbeddedBlock(t *testing.T) { + const address = "0x3333333333333333333333333333333333333333" + + var gotBlock rpc.BlockNumber + + resolver := &logResolver{&Resolver{ + GraphQLAPI: mockGraphQLAPI{ + getAccountInfo: func(_ context.Context, _ common.Address, blockNumber rpc.BlockNumber) (string, uint64, string, error) { + gotBlock = blockNumber + return "0x20", 3, "0x6001", nil + }, + }, + }} + + logEntry := &model.Log{Account: model.NewAccountAtBlock(55)} + logEntry.Account.Address = address + + account, err := resolver.Account(context.Background(), logEntry, nil) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if gotBlock != rpc.BlockNumber(55) { + t.Fatalf("expected embedded block 55, got %d", gotBlock) + } + if account.BlockNum != 55 { + t.Fatalf("expected result block 55, got %d", account.BlockNum) + } +} + +func TestTransactionResolverFromRejectsOverflowRequestedBlock(t *testing.T) { + const address = "0x1111111111111111111111111111111111111111" + + called := false + resolver := &transactionResolver{&Resolver{ + GraphQLAPI: mockGraphQLAPI{ + getAccountInfo: func(_ context.Context, _ common.Address, _ rpc.BlockNumber) (string, uint64, string, error) { + called = true + return "0x10", 7, "0x6000", nil + }, + }, + }} + + tx := &model.Transaction{From: model.NewAccountAtBlock(12)} + tx.From.Address = address + overflow := uint64(math.MaxInt64) + 1 + + _, err := resolver.From(context.Background(), tx, &overflow) + if err == nil { + t.Fatal("expected overflow error, got nil") + } + if called { + t.Fatal("expected resolver to reject overflow before GetAccountInfo call") + } +} + func TestBlockResolver_TransactionAt(t *testing.T) { r := &blockResolver{&Resolver{}}