diff --git a/services/explorer/consumer/client/resolver-client/server.go b/services/explorer/consumer/client/resolver-client/server.go index c86cee32c2..81e6233eeb 100644 --- a/services/explorer/consumer/client/resolver-client/server.go +++ b/services/explorer/consumer/client/resolver-client/server.go @@ -80,7 +80,7 @@ type ComplexityRoot struct { LogCount func(childComplexity int, contractAddress string, chainID int) int Logs func(childComplexity int, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, page int) int LogsAtHeadRange func(childComplexity int, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int) int - LogsRange func(childComplexity int, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int) int + LogsRange func(childComplexity int, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int, asc *bool) int ReceiptCount func(childComplexity int, chainID int) int Receipts func(childComplexity int, chainID int, txHash *string, contractAddress *string, blockHash *string, blockNumber *int, txIndex *int, confirmed *bool, page int) int ReceiptsAtHeadRange func(childComplexity int, chainID int, txHash *string, contractAddress *string, blockHash *string, blockNumber *int, txIndex *int, confirmed *bool, startBlock int, endBlock int, page int) int @@ -138,7 +138,7 @@ type LogResolver interface { } type QueryResolver interface { Logs(ctx context.Context, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, page int) ([]*model.Log, error) - LogsRange(ctx context.Context, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int) ([]*model.Log, error) + LogsRange(ctx context.Context, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int, asc *bool) ([]*model.Log, error) Receipts(ctx context.Context, chainID int, txHash *string, contractAddress *string, blockHash *string, blockNumber *int, txIndex *int, confirmed *bool, page int) ([]*model.Receipt, error) ReceiptsRange(ctx context.Context, chainID int, txHash *string, contractAddress *string, blockHash *string, blockNumber *int, txIndex *int, confirmed *bool, startBlock int, endBlock int, page int) ([]*model.Receipt, error) Transactions(ctx context.Context, txHash *string, chainID int, blockNumber *int, blockHash *string, confirmed *bool, page int) ([]*model.Transaction, error) @@ -419,7 +419,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.LogsRange(childComplexity, args["contract_address"].(*string), args["chain_id"].(int), args["block_number"].(*int), args["tx_hash"].(*string), args["tx_index"].(*int), args["block_hash"].(*string), args["index"].(*int), args["confirmed"].(*bool), args["start_block"].(int), args["end_block"].(int), args["page"].(int)), true + return e.complexity.Query.LogsRange(childComplexity, args["contract_address"].(*string), args["chain_id"].(int), args["block_number"].(*int), args["tx_hash"].(*string), args["tx_index"].(*int), args["block_hash"].(*string), args["index"].(*int), args["confirmed"].(*bool), args["start_block"].(int), args["end_block"].(int), args["page"].(int), args["asc"].(*bool)), true case "Query.receiptCount": if e.complexity.Query.ReceiptCount == nil { @@ -873,6 +873,7 @@ directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITI start_block: Int! end_block: Int! page: Int! + asc: Boolean = False ): [Log] # returns all receipts that match the given filter receipts( @@ -1427,6 +1428,15 @@ func (ec *executionContext) field_Query_logsRange_args(ctx context.Context, rawA } } args["page"] = arg10 + var arg11 *bool + if tmp, ok := rawArgs["asc"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("asc")) + arg11, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["asc"] = arg11 return args, nil } @@ -3003,7 +3013,7 @@ func (ec *executionContext) _Query_logsRange(ctx context.Context, field graphql. }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().LogsRange(rctx, fc.Args["contract_address"].(*string), fc.Args["chain_id"].(int), fc.Args["block_number"].(*int), fc.Args["tx_hash"].(*string), fc.Args["tx_index"].(*int), fc.Args["block_hash"].(*string), fc.Args["index"].(*int), fc.Args["confirmed"].(*bool), fc.Args["start_block"].(int), fc.Args["end_block"].(int), fc.Args["page"].(int)) + return ec.resolvers.Query().LogsRange(rctx, fc.Args["contract_address"].(*string), fc.Args["chain_id"].(int), fc.Args["block_number"].(*int), fc.Args["tx_hash"].(*string), fc.Args["tx_index"].(*int), fc.Args["block_hash"].(*string), fc.Args["index"].(*int), fc.Args["confirmed"].(*bool), fc.Args["start_block"].(int), fc.Args["end_block"].(int), fc.Args["page"].(int), fc.Args["asc"].(*bool)) }) if err != nil { ec.Error(ctx, err) diff --git a/services/scribe/api/data_test.go b/services/scribe/api/data_test.go index 2dc1fb8b98..58d2a43d15 100644 --- a/services/scribe/api/data_test.go +++ b/services/scribe/api/data_test.go @@ -5,6 +5,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" . "github.com/stretchr/testify/assert" + "github.com/synapsecns/sanguine/core" "github.com/synapsecns/sanguine/services/scribe/db" "github.com/synapsecns/sanguine/services/scribe/graphql" "github.com/synapsecns/sanguine/services/scribe/grpc/client/rest" @@ -51,13 +52,13 @@ func (g APISuite) TestRetrieveData() { Nil(g.T(), err) // there were 20 logs created (2 per loop, in a loop of 10) Equal(g.T(), 20, len(logs.Response)) - logsRange, err := g.gqlClient.GetLogsRange(g.GetTestContext(), int(chainID), 2, 5, 1) + logsRange, err := g.gqlClient.GetLogsRange(g.GetTestContext(), int(chainID), 2, 5, 1, nil) Nil(g.T(), err) // from 2-5, there were 8 logs created (2 per loop, in a range of 4) Equal(g.T(), 8, len(logsRange.Response)) // Test getting logs in a range in ascending order. - logsRangeAsc, err := g.gqlClient.GetLogsRange(g.GetTestContext(), int(chainID), 5, 2, 1) + logsRangeAsc, err := g.gqlClient.GetLogsRange(g.GetTestContext(), int(chainID), 2, 5, 1, core.PtrTo(true)) Nil(g.T(), err) Equal(g.T(), 8, len(logsRangeAsc.Response)) Equal(g.T(), 2, logsRangeAsc.Response[0].BlockNumber) diff --git a/services/scribe/cmd/cmd.md b/services/scribe/cmd/cmd.md index 890138bd43..0ce170541e 100644 --- a/services/scribe/cmd/cmd.md +++ b/services/scribe/cmd/cmd.md @@ -5,7 +5,7 @@ Scribe is a multi-chain indexing service. Scribe is designed to take a list of contracts specified by chain id and store logs, receipts, and txs for every event, past to present, in a mysql database. Use cases -- Analytics for on chain events +- Analytics for on-chain events - Stream events occurring across chains - Monitor activity on your contracts diff --git a/services/scribe/graphql/client/client.go b/services/scribe/graphql/client/client.go index a02ed9a1f3..1948d4d429 100644 --- a/services/scribe/graphql/client/client.go +++ b/services/scribe/graphql/client/client.go @@ -327,8 +327,8 @@ func (c *Client) GetLogs(ctx context.Context, chainID int, page int, httpRequest return &res, nil } -const GetLogsRangeDocument = `query GetLogsRange ($chain_id: Int!, $start_block: Int!, $end_block: Int!, $page: Int!) { - response: logsRange(chain_id: $chain_id, start_block: $start_block, end_block: $end_block, page: $page) { +const GetLogsRangeDocument = `query GetLogsRange ($chain_id: Int!, $start_block: Int!, $end_block: Int!, $page: Int!, $asc: Boolean = false) { + response: logsRange(chain_id: $chain_id, start_block: $start_block, end_block: $end_block, page: $page, asc: $asc) { contract_address chain_id topics @@ -343,12 +343,13 @@ const GetLogsRangeDocument = `query GetLogsRange ($chain_id: Int!, $start_block: } ` -func (c *Client) GetLogsRange(ctx context.Context, chainID int, startBlock int, endBlock int, page int, httpRequestOptions ...client.HTTPRequestOption) (*GetLogsRange, error) { +func (c *Client) GetLogsRange(ctx context.Context, chainID int, startBlock int, endBlock int, page int, asc *bool, httpRequestOptions ...client.HTTPRequestOption) (*GetLogsRange, error) { vars := map[string]interface{}{ "chain_id": chainID, "start_block": startBlock, "end_block": endBlock, "page": page, + "asc": asc, } var res GetLogsRange diff --git a/services/scribe/graphql/client/queries/queries.graphql b/services/scribe/graphql/client/queries/queries.graphql index 19e6238462..2e6d1c0a9b 100644 --- a/services/scribe/graphql/client/queries/queries.graphql +++ b/services/scribe/graphql/client/queries/queries.graphql @@ -13,8 +13,8 @@ query GetLogs ($chain_id: Int!, $page: Int!) { } } -query GetLogsRange ($chain_id: Int!, $start_block: Int!, $end_block: Int!, $page: Int!) { - response: logsRange (chain_id: $chain_id, start_block: $start_block, end_block: $end_block, page: $page) { +query GetLogsRange ($chain_id: Int!, $start_block: Int!, $end_block: Int!, $page: Int!, $asc: Boolean = false) { + response: logsRange (chain_id: $chain_id, start_block: $start_block, end_block: $end_block, page: $page,asc: $asc) { contract_address chain_id topics diff --git a/services/scribe/graphql/server/graph/queries.resolvers.go b/services/scribe/graphql/server/graph/queries.resolvers.go index 2ec0985382..7b4e43c7d9 100644 --- a/services/scribe/graphql/server/graph/queries.resolvers.go +++ b/services/scribe/graphql/server/graph/queries.resolvers.go @@ -31,14 +31,14 @@ func (r *queryResolver) Logs(ctx context.Context, contractAddress *string, chain } // LogsRange is the resolver for the logsRange field. -func (r *queryResolver) LogsRange(ctx context.Context, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int) ([]*model.Log, error) { +func (r *queryResolver) LogsRange(ctx context.Context, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int, asc *bool) ([]*model.Log, error) { logsFilter := db.BuildLogFilter(contractAddress, blockNumber, txHash, txIndex, blockHash, index, confirmed) logsFilter.ChainID = uint32(chainID) var logs []*types.Log var err error - // Get logs in ascending order if startBlock > endBlock - if startBlock > endBlock { - logs, err = r.DB.RetrieveLogsInRangeAsc(ctx, logsFilter, uint64(endBlock), uint64(startBlock), page) + // Get logs in ascending order if asc is set to true. + if asc != nil && *asc { + logs, err = r.DB.RetrieveLogsInRangeAsc(ctx, logsFilter, uint64(startBlock), uint64(endBlock), page) } else { logs, err = r.DB.RetrieveLogsInRange(ctx, logsFilter, uint64(startBlock), uint64(endBlock), page) } diff --git a/services/scribe/graphql/server/graph/resolver/server.go b/services/scribe/graphql/server/graph/resolver/server.go index 05fb0627d9..e41227f81d 100644 --- a/services/scribe/graphql/server/graph/resolver/server.go +++ b/services/scribe/graphql/server/graph/resolver/server.go @@ -80,7 +80,7 @@ type ComplexityRoot struct { LogCount func(childComplexity int, contractAddress string, chainID int) int Logs func(childComplexity int, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, page int) int LogsAtHeadRange func(childComplexity int, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int) int - LogsRange func(childComplexity int, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int) int + LogsRange func(childComplexity int, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int, asc *bool) int ReceiptCount func(childComplexity int, chainID int) int Receipts func(childComplexity int, chainID int, txHash *string, contractAddress *string, blockHash *string, blockNumber *int, txIndex *int, confirmed *bool, page int) int ReceiptsAtHeadRange func(childComplexity int, chainID int, txHash *string, contractAddress *string, blockHash *string, blockNumber *int, txIndex *int, confirmed *bool, startBlock int, endBlock int, page int) int @@ -138,7 +138,7 @@ type LogResolver interface { } type QueryResolver interface { Logs(ctx context.Context, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, page int) ([]*model.Log, error) - LogsRange(ctx context.Context, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int) ([]*model.Log, error) + LogsRange(ctx context.Context, contractAddress *string, chainID int, blockNumber *int, txHash *string, txIndex *int, blockHash *string, index *int, confirmed *bool, startBlock int, endBlock int, page int, asc *bool) ([]*model.Log, error) Receipts(ctx context.Context, chainID int, txHash *string, contractAddress *string, blockHash *string, blockNumber *int, txIndex *int, confirmed *bool, page int) ([]*model.Receipt, error) ReceiptsRange(ctx context.Context, chainID int, txHash *string, contractAddress *string, blockHash *string, blockNumber *int, txIndex *int, confirmed *bool, startBlock int, endBlock int, page int) ([]*model.Receipt, error) Transactions(ctx context.Context, txHash *string, chainID int, blockNumber *int, blockHash *string, confirmed *bool, page int) ([]*model.Transaction, error) @@ -419,7 +419,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.LogsRange(childComplexity, args["contract_address"].(*string), args["chain_id"].(int), args["block_number"].(*int), args["tx_hash"].(*string), args["tx_index"].(*int), args["block_hash"].(*string), args["index"].(*int), args["confirmed"].(*bool), args["start_block"].(int), args["end_block"].(int), args["page"].(int)), true + return e.complexity.Query.LogsRange(childComplexity, args["contract_address"].(*string), args["chain_id"].(int), args["block_number"].(*int), args["tx_hash"].(*string), args["tx_index"].(*int), args["block_hash"].(*string), args["index"].(*int), args["confirmed"].(*bool), args["start_block"].(int), args["end_block"].(int), args["page"].(int), args["asc"].(*bool)), true case "Query.receiptCount": if e.complexity.Query.ReceiptCount == nil { @@ -873,6 +873,7 @@ directive @goField(forceResolver: Boolean, name: String) on INPUT_FIELD_DEFINITI start_block: Int! end_block: Int! page: Int! + asc: Boolean = False ): [Log] # returns all receipts that match the given filter receipts( @@ -1427,6 +1428,15 @@ func (ec *executionContext) field_Query_logsRange_args(ctx context.Context, rawA } } args["page"] = arg10 + var arg11 *bool + if tmp, ok := rawArgs["asc"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("asc")) + arg11, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["asc"] = arg11 return args, nil } @@ -3003,7 +3013,7 @@ func (ec *executionContext) _Query_logsRange(ctx context.Context, field graphql. }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().LogsRange(rctx, fc.Args["contract_address"].(*string), fc.Args["chain_id"].(int), fc.Args["block_number"].(*int), fc.Args["tx_hash"].(*string), fc.Args["tx_index"].(*int), fc.Args["block_hash"].(*string), fc.Args["index"].(*int), fc.Args["confirmed"].(*bool), fc.Args["start_block"].(int), fc.Args["end_block"].(int), fc.Args["page"].(int)) + return ec.resolvers.Query().LogsRange(rctx, fc.Args["contract_address"].(*string), fc.Args["chain_id"].(int), fc.Args["block_number"].(*int), fc.Args["tx_hash"].(*string), fc.Args["tx_index"].(*int), fc.Args["block_hash"].(*string), fc.Args["index"].(*int), fc.Args["confirmed"].(*bool), fc.Args["start_block"].(int), fc.Args["end_block"].(int), fc.Args["page"].(int), fc.Args["asc"].(*bool)) }) if err != nil { ec.Error(ctx, err) diff --git a/services/scribe/graphql/server/graph/schema/queries.graphql b/services/scribe/graphql/server/graph/schema/queries.graphql index aaa237ed3d..043edfde31 100644 --- a/services/scribe/graphql/server/graph/schema/queries.graphql +++ b/services/scribe/graphql/server/graph/schema/queries.graphql @@ -24,6 +24,7 @@ type Query { start_block: Int! end_block: Int! page: Int! + asc: Boolean = False ): [Log] # returns all receipts that match the given filter receipts( diff --git a/services/scribe/service/indexer/indexer_test.go b/services/scribe/service/indexer/indexer_test.go index 43e17286cb..5bf341bc03 100644 --- a/services/scribe/service/indexer/indexer_test.go +++ b/services/scribe/service/indexer/indexer_test.go @@ -467,7 +467,7 @@ func (x *IndexerSuite) TestTxTypeNotSupported() { } var backendClient backend.ScribeBackend - omnirpcURL := "https://rpc.interoperability.institute/confirmations/1/rpc/42161" + omnirpcURL := "https://arbitrum.llamarpc.com" backendClient, err := backend.DialBackend(x.GetTestContext(), omnirpcURL, x.metrics) Nil(x.T(), err)