code.vegaprotocol.io/vega@v0.79.0/datanode/entities/ledgerentry_filter.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package entities 17 18 import ( 19 v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2" 20 "code.vegaprotocol.io/vega/protos/vega" 21 ) 22 23 // CloseOnLimitOperation is the type that is used for opening and closing the set of output items under some operation. 24 // Intended for generic use. 25 type CloseOnLimitOperation bool 26 27 // LedgerEntryFilter settings for receiving closed/open sets on different parts of the outputs of LedgerEntries. 28 // Any kind of relation between the data types on logical and practical level in the set is the `limit operation`. 29 // We close or not the set of output items on the limit operation via the `CloseOnOperation` set values. 30 type LedgerEntryFilter struct { 31 // CloseOnAccountFilters is used to open/close the output set of entries under the FromAccount/ToAccount values. 32 // If true -> the output set will contain entries which sending and receiving accounts 33 // all match the criteria given in the `AccountFilter` type. 34 // Otherwise will contain entries that have a match the settings in both accounts (sending or receiving) or in one of them. 35 CloseOnAccountFilters CloseOnLimitOperation 36 // FromAccountFilter is a filter which is used to request properties for FromAccount field. 37 FromAccountFilter AccountFilter 38 // ToAccountFilter is a filter which is used to request properties for ToAccount field. 39 ToAccountFilter AccountFilter 40 41 // Filter on LedgerMovementType 42 TransferTypes []LedgerMovementType 43 44 // Transfer ID to filter by 45 TransferID TransferID 46 } 47 48 func LedgerEntryFilterFromProto(pbFilter *v2.LedgerEntryFilter) (*LedgerEntryFilter, error) { 49 filter := LedgerEntryFilter{} 50 if pbFilter != nil { 51 filter.CloseOnAccountFilters = CloseOnLimitOperation(pbFilter.CloseOnAccountFilters) 52 53 var err error 54 filter.FromAccountFilter, err = AccountFilterFromProto(pbFilter.FromAccountFilter) 55 if err != nil { 56 return nil, err 57 } 58 filter.ToAccountFilter, err = AccountFilterFromProto(pbFilter.ToAccountFilter) 59 if err != nil { 60 return nil, err 61 } 62 63 if len(pbFilter.TransferTypes) > 0 { 64 filter.TransferTypes = make([]LedgerMovementType, len(pbFilter.TransferTypes)) 65 for i, tt := range pbFilter.TransferTypes { 66 t, ok := vega.TransferType_value[tt.String()] 67 if ok { 68 filter.TransferTypes[i] = LedgerMovementType(t) 69 } 70 } 71 } 72 73 if pbFilter.TransferId != nil { 74 filter.TransferID = TransferID(*pbFilter.TransferId) 75 } 76 } 77 78 return &filter, nil 79 }