From 373f1414c5b95206251b6c2d9ef80b9a5a7665bc Mon Sep 17 00:00:00 2001 From: Tan Quach <30750203+guoguojin@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:40:33 +0000 Subject: [PATCH] Merge pull request #10117 from vegaprotocol/fix/10103-list-ledger-entries-filter-transfer-type fix: update documentation and improve error message --- CHANGELOG.md | 1 + datanode/api/trading_data_v2.go | 3 ++ datanode/gateway/graphql/schema.graphql | 14 +++++++++- datanode/sqlstore/ledger_test.go | 28 +++++++++++++++++++ .../data-node/api/v2/trading_data_grpc.pb.go | 14 ++++++++++ .../data-node/api/v2/trading_data.proto | 5 ++++ 6 files changed, 64 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 847655aed9..cd24bdd8f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### 🐛 Fixes - [9940](https://github.com/vegaprotocol/vega/issues/9940) - Do not assume stop order is valid when generating ids up front. +- [10103](https://github.com/vegaprotocol/vega/issues/10103) - List ledgers `API` returns bad error when filtering by transfer type only. ## 0.73.4 diff --git a/datanode/api/trading_data_v2.go b/datanode/api/trading_data_v2.go index 987bf94698..486eb5c7f8 100644 --- a/datanode/api/trading_data_v2.go +++ b/datanode/api/trading_data_v2.go @@ -435,6 +435,9 @@ func (t *TradingDataServiceV2) ListLedgerEntries(ctx context.Context, req *v2.Li entries, pageInfo, err := t.ledgerService.Query(ctx, leFilter, dateRange, pagination) if err != nil { + if errors.Is(err, sqlstore.ErrLedgerEntryFilterForParty) { + return nil, formatE(ErrInvalidFilter, err) + } return nil, formatE(ErrLedgerServiceGet, err) } diff --git a/datanode/gateway/graphql/schema.graphql b/datanode/gateway/graphql/schema.graphql index 9200dbf3cf..f324b204e1 100644 --- a/datanode/gateway/graphql/schema.graphql +++ b/datanode/gateway/graphql/schema.graphql @@ -686,7 +686,19 @@ type Query { ): MarketDataConnection """ - Get ledger entries by asset, market, party, account type, transfer type within the given date range. + Get a list of ledger entries within the given date range. The date range is restricted to a maximum of 5 days. + This query requests and sums the number of ledger entries from a given subset of accounts, specified via the 'filter' argument. + It returns a time series - implemented as a list of AggregateLedgerEntry structs - with a row for every time + the summed ledger entries of the set of specified accounts changes. + Each account filter must contain no more than one party ID. + At least one party ID must be specified in the from or to account filter. + + Entries can be filtered by: + - the sending account (market ID, asset ID, account type) + - receiving account (market ID, asset ID, account type) + - sending AND receiving account + - transfer type either in addition to the above filters or as a standalone option + Note: The date range is restricted to any 5 days. If no start or end date is provided, only ledger entries from the last 5 days will be returned. If a start and end date are provided, but the end date is more than 5 days after the start date, only data up to 5 days after the start date will be returned. diff --git a/datanode/sqlstore/ledger_test.go b/datanode/sqlstore/ledger_test.go index 3d02ed2871..bd9d299a8d 100644 --- a/datanode/sqlstore/ledger_test.go +++ b/datanode/sqlstore/ledger_test.go @@ -780,6 +780,34 @@ func TestLedger(t *testing.T) { assert.Equal(t, 0, len(*entries)) }) + t.Run("by transferType only", func(t *testing.T) { + // open on account filters + // Set filters for FromAccount and AcountTo IDs + filter := &entities.LedgerEntryFilter{ + TransferTypes: []entities.LedgerMovementType{ + entities.LedgerMovementTypeDeposit, + }, + } + + _, _, err := ledgerStore.Query(ctx, + filter, + entities.DateRange{Start: &tStart, End: &tEnd}, + entities.CursorPagination{}, + ) + + assert.Error(t, err) + + // closed on account filters + filter.CloseOnAccountFilters = true + _, _, err = ledgerStore.Query(ctx, + filter, + entities.DateRange{Start: &tStart, End: &tEnd}, + entities.CursorPagination{}, + ) + + assert.Error(t, err) + }) + t.Run("test open/closing with different account and transfer types", func(t *testing.T) { filter := &entities.LedgerEntryFilter{ FromAccountFilter: entities.AccountFilter{ diff --git a/protos/data-node/api/v2/trading_data_grpc.pb.go b/protos/data-node/api/v2/trading_data_grpc.pb.go index 2b1ed6a43e..ab78bf53f9 100644 --- a/protos/data-node/api/v2/trading_data_grpc.pb.go +++ b/protos/data-node/api/v2/trading_data_grpc.pb.go @@ -91,6 +91,13 @@ type TradingDataServiceClient interface { // - receiving account (market ID, asset ID, account type) // - sending AND receiving account // - transfer type either in addition to the above filters or as a standalone option + // + // Note: The date range is restricted to any 5 days. + // + // If no start or end date is provided, only ledger entries from the last 5 days will be returned. + // If a start and end date are provided, but the end date is more than 5 days after the start date, only data up to 5 days after the start date will be returned. + // If a start date is provided but no end date, the end date will be set to 5 days after the start date. + // If no start date is provided, but the end date is, the start date will be set to 5 days before the end date. ListLedgerEntries(ctx context.Context, in *ListLedgerEntriesRequest, opts ...grpc.CallOption) (*ListLedgerEntriesResponse, error) // Export ledger entries // @@ -2038,6 +2045,13 @@ type TradingDataServiceServer interface { // - receiving account (market ID, asset ID, account type) // - sending AND receiving account // - transfer type either in addition to the above filters or as a standalone option + // + // Note: The date range is restricted to any 5 days. + // + // If no start or end date is provided, only ledger entries from the last 5 days will be returned. + // If a start and end date are provided, but the end date is more than 5 days after the start date, only data up to 5 days after the start date will be returned. + // If a start date is provided but no end date, the end date will be set to 5 days after the start date. + // If no start date is provided, but the end date is, the start date will be set to 5 days before the end date. ListLedgerEntries(context.Context, *ListLedgerEntriesRequest) (*ListLedgerEntriesResponse, error) // Export ledger entries // diff --git a/protos/sources/data-node/api/v2/trading_data.proto b/protos/sources/data-node/api/v2/trading_data.proto index 6284797215..a136fdbcc7 100644 --- a/protos/sources/data-node/api/v2/trading_data.proto +++ b/protos/sources/data-node/api/v2/trading_data.proto @@ -141,6 +141,11 @@ service TradingDataService { // - receiving account (market ID, asset ID, account type) // - sending AND receiving account // - transfer type either in addition to the above filters or as a standalone option + // Note: The date range is restricted to any 5 days. + // If no start or end date is provided, only ledger entries from the last 5 days will be returned. + // If a start and end date are provided, but the end date is more than 5 days after the start date, only data up to 5 days after the start date will be returned. + // If a start date is provided but no end date, the end date will be set to 5 days after the start date. + // If no start date is provided, but the end date is, the start date will be set to 5 days before the end date. rpc ListLedgerEntries(ListLedgerEntriesRequest) returns (ListLedgerEntriesResponse) { option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "Ledger entries"}; }