Skip to content

Commit

Permalink
Merge pull request #10117 from vegaprotocol/fix/10103-list-ledger-ent…
Browse files Browse the repository at this point in the history
…ries-filter-transfer-type

fix: update documentation and improve error message
  • Loading branch information
guoguojin authored and jeremyletang committed Nov 17, 2023
1 parent 5984f76 commit 373f141
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions datanode/api/trading_data_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
14 changes: 13 additions & 1 deletion datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions datanode/sqlstore/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
14 changes: 14 additions & 0 deletions protos/data-node/api/v2/trading_data_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions protos/sources/data-node/api/v2/trading_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
}
Expand Down

0 comments on commit 373f141

Please sign in to comment.